The GoBox API
Introduction
The GoBox API enables outside applications to make call to acquire GoBox User data. All calls are available to GoBox Developers through a standard Rest-based format. If you don't have a GoBox account, Sign up now for a FREE account.
Request Format
The GoBox API uses a RESTful calling style that works with standard HTTP calls. Any web programming language (PHP, Ruby, Perl, Python, Java, Objective C, C#...) should be able to make and receive HTTP networking calls; consult the documentation for your language of choice.
Request Limit
If you think you need more, please request a higher call limit by emailing admin@gobox.com.
- Limit calls to 5,000 per day, per API key
- Limit queries to 2 per second, per API key
PHP Example
Prerequisites
- PHP4 or higher
- cURL
GoBoxClient.php
<?php
class GoBoxClient
{
// The key, secret and server for the api server
// Developers should substitue their apikey and secret here
var $_format = "xml";
var $_server = "http://api.gobox.com/rest/";
var $_apikey = ""; //mashery key
var $_secret = ""; //gobox shared secret
/*
* Constructor that takes values for server, key and secret
*/
function GoBoxClient($server = null, $apikey = null, $secret = null, $format = null, $version = null)
{
if($server != null)
{
$this->_server = $server;
}
if($format != null)
{
$this->_format = $format;
}
if($apikey != null)
{
$this->_apikey = $apikey;
}
if($secret != null)
{
$this->_secret = $secret;
}
return true;
}
/*
* Build a signed request url for the API
*/
function getRequestURL($method, $_params)
{
$params['format'] = $this->_format;
$params['api_key'] = $this->_apikey;
$timestamp = time();
$params['time_stamp'] = $timestamp;
// Start building the URL string with the server and method
$requestUrl = $this->_server . "/$method?";
// Copy the passed in parameters into the default parameter
if($_params)
{
foreach($_params as $key => $val)
{
$params[$key] = $val;
}
}
// Generate the signature from the api_key and secret in the params
$params['sig'] = $this->getSignature($this->_apikey,$this->_secret, $timestamp);
// Append the param keys and alues to the URL string
foreach($params as $key => $val)
{
$requestUrl .= "$key=" . urlencode($val) . "&";
}
return $requestUrl;
}
/*
* Get a URL signature value for a particular key and secret
*/
function getSignature($api_key, $secret, $timestamp)
{
$sig = md5($api_key.$secret.$timestamp);
return $sig;
}
/*
* Make the api request over HTTP
*/
function sendAPIRequest($url)
{
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// Handle any HTTP errors by simply returning the error message string
if (curl_errno($ch))
{
$response = curl_error($ch);
} else {
curl_close($ch); // make sure the connection is closed
}
return $response;
}
}
?>
GoBoxAPIExample.php
<?php /* * Example of how to use the GoBoxClient class. * */ require_once("GoBoxClient.php"); // Instantiate the client object with default values $client = new GoBoxClient(); // make a call $request = $client->getRequestURL("items/items_list",array("page" => "1", "results_per_a_page" => "30", "sort_field" => "name", "sort_order" => "asc", "format" => "xml")); print("Request :$request\n"); $response = $client->sendAPIRequest($request); print("Response :$response\n"); ?>