Using the Rest API

From LabTrove Documentation
Jump to: navigation, search

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:
  1. Login to your Trove.
  2. Select a post that you created.
  3. Click your author name at the bottom of the post. A page listing your posts, comments, and user information displays.
  4. Scroll down to the bottom of the page, copy your Master UID hash code.
  5. 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 Notebook on the server located at issue the following request, followed by the XML data:

Sample PHP code for issuing an addpost request


$url = "";  // Obtain your_hash_code as described above
$xml = <<<END
<?xml version="1.0" encoding="UTF-8"?> 
  Refer to the example in the 'Adding a post' topic below

$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
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.