Using the Rest API
Introduction to the REST-like API
The LabTrove REST-like API enables you to add a post, edit an existing post, or add data to a post. To make calls to the LabTrove REST API, use the HTTP POST request method. This topic describes how to construct the POST request and provides examples of the XML data that you send in the body of the HTTP request. The examples topics also explain the XML response that LabTrove returns when you use its REST API.
You can use any programming method for accessing web servers.
Assembling the POST request
Construct the request string as /api/rest/<action>/uid/<uid>, where:
- <action> can be:
addpost | editpost | appendpost | adddata
- <uid> is a hash code specific to your user ID, which you obtain as follows:
- Login to your Trove.
- Select a post that you created.
- Click your author name at the bottom of the post. A page listing your posts, comments, and user information displays.
- Scroll down to the bottom of the page, copy your Master UID hash code.
- Paste the hash code into the request string.
Append the request string to the LabTrove server URL to construct the POST request. For example, to add a post to a E-notebook on the server located at http://www.ourexperiment.org/ issue the following request, followed by the XML data:
Sample PHP code for issuing an addpost request
<?php $url = "http://www.ourexperiment.org/api/rest/addpost/uid/your_hash_code"; // Obtain your_hash_code as described above $xml = <<<END <?xml version="1.0" encoding="UTF-8"?> <post> Refer to the example in the 'Adding a post' topic below </post> END; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST ,1); curl_setopt($ch, CURLOPT_POSTFIELDS ,array("request"=>$xml)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL echo $response = curl_exec($ch); ?>
Examples of calls to the REST API
The following pages provide examples of the XML data that you send with each <action> and help you to understand the LabTrove response:
What to do next
- For information about status and reason codes from LabTrove, see Status codes.