Bioenergy KDF REST API

Introduction

This document is intended for developers wishing to write applications that can interact with the Bioenergy KDF REST API.  You can use the RESTful API to search and retrieve content harnessed in BioenergyKDF.net programmatically. For additional help with this API please use the contact form.

 

API Documentation

Response Formats:

The REST API supports both the JSON, JSONP and XML data serialization formats. XML is currently the default format for both requests and responses. The format for both the request and the response can be specified either using the Content-Type header, the Accept header or adding  .json or .xml  extension to the request URI for JSON and xml respectively. JSONP can be requested using the callback parameter in the url.
If conflicting formats are specified in headers and/or format extensions, the latter takes precedence.

Format Accept header Query Extension Default
JSON application/json .json No
JSONP application/javascript N/A (use callback parameter) No
XML application/xml .xml Yes

 

Services:

 

Tools and Apps:

Services to access tools and apps

Name Documentation Status
Billion Ton API Documentation
Model Documentation
available

 

Login: 

(not available yet)

Login into bioenergykdf.net using the username and password of a user. Once logged in the response will be the user logged in object and a session_id and a session name. You can use this the session_id and session name to make further api requests.

URL: https://bioenergykdf.net/api/rest/user/login

HTTP Method: POST

Parameters:
Name Type Description
username String The username
password String The password

Logout:

(not available yet)

Terminates the session for a user. This method does not require any parameters.

URL: https://bioenergykdf.net/api/rest/user/login

HTTP Method: POST

Content Search:

(not available yet)

Search for content based on keywords or content types. You can use the page parameter to get paged results.

URL: https://bioenergykdf.net/api/rest/content

HTTP Method: GET

Parameters:

Name Type Description
search_string String String to search in the titles
type Enum Type of content to return
'map_service' for Map data
'data_file' for Documents and other data
'web_resource' for Web Links
types[] Enum Same as type values, but can include multiple of these. (e.g. types[]=map_serivice&type=data_file)
title String String to match the titles (this is an exact match unline search_string)
sort Enum Sort order
'created' for sorting based on when nodes are created on the site
'changed' for sorting based on last updated time stamp
'nid' for sorting based on node ids
sort_order Enum ASC or DESC
limit int The number of items to return in a single request
page int The page number of results to return (e.g. page=1 returns results from 10 - 20)


Node:

(not available yet)

Get content of a node. Node is a sigle entity (map_service, document or web link).

URL: https://bioenergykdf.net/api/rest/node

HTTP Method: GET

Parameters:
Name Type Description
nid int id of the node to retrieve

 

Example Client Code:

<?php

/*

 * Server REST - user.login

 */



// REST Server URL
$request_url = 'http://your-drupal/rest_server_endpoint/user/login';


// User data
$user_data = array(
  'username' => 'user_name',
  'password' => 'user_password',
);
$user_data = http_build_query($user_data);


// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $user_data); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE);  // Ask to not return Header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);

$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

// Check if login was successful
if ($http_code == 200) {
  // Convert json response as array
  $logged_user = json_decode($response);
}
else {
  // Get error msg
  $http_message = curl_error($curl);
  die($http_message);
}



/*

 * Server REST - node

 */

// REST Server URL
$request_url = 'https://bioenergykdf.net/api/rest/node';

// data
$params = array(
  'nid' => 55
);
$params = http_build_query($params);

// Define cookie session
$cookie_session = $logged_user->session_name . '=' .$logged_user->sessid;

// cURL
$curl = curl_init($request_url.$params);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON response
curl_setopt($curl, CURLOPT_HEADER, FALSE);  // Ask to not return Header
curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);

$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);


// Check if request was successful

if ($http_code == 200) {
  // Convert json response as array
  $node = json_decode($response);
}
else {
  // Get error msg
  $http_message = curl_error($curl);
  die($http_message);
}

//Do something with $node

?>