We allow developers to integrate our service into other software applications that can connect to the web. For example, a carbon accounting software may add benchmarking features or carbon credit analysis tools may refine their predictive algorithms with our data.
Our XML web services are based on the latest SOAP standards and expose 4 functions:
The complete WSDL file can be viewed at http://co2benchmark.com/services/soap?wsdl and a PHP code example is provided below.
We require developers to obtain an API key in order to start using our services. These can simply be obtained by using our contact form. The usage rights will be analysed on a case-by-case basis.
PHP Code example to obtain Company Benchmarking data ('Chart2'):
<?php
/**
* WSDL client for http://co2benchmark.com web API
* @version 1.0
*
*/
/**
* php_soap.dll extension needed to test it
* to enable set in your php.ini file
* extension=php_soap.dll
*/
if (!extension_loaded ('soap'))
{
die('You need to enable SOAP extension in your php.ini file to make this script work.');
}
$param = array();
/**
* Setup all variables
*/
// URL
$wsdl = "http://co2benchmark.com/services/soap?wsdl";
$domain = $_SERVER['HTTP_HOST'];
// API key
$api_key = 'abcdef123456789abc133454abcde3334567'; // put here the API key you obtained from us
// api method to test
$method_name = 'form_query.getDataChart2';
$timestamp = time();
$nonce = createRandomString();
$hash = generateHash($timestamp, $domain, $nonce, $api_key, $method_name);
// next 4 are required when API_KEY security is on, do not change
$param ['hash'] = $hash;
$param ['domain_name'] = $domain;
$param ['domain_time_stamp'] = $timestamp;
$param ['nonce'] = $nonce;
// custom params
$param ['industryId'] = 68;
$param ['employees'] = 99; // specify employees number or turnover value
$param ['turnover'] = 0;
$param ['countryId'] = 4;
$param ['year'] = 2007;
/**
* Prepare client
*/
$client = new SoapClient($wsdl,
array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
)
);
/**
* Make call and output results
*/
$result = $client->__soapCall($method_name, $param);
echo "<pre>Connecting to '$wsdl' with '$api_key' API key</pre><br/>\n";
echo "Request params are:<br/>\n";
echo '<pre>';print_r($param);echo '</pre>';
echo "Response:<br/>\n";
echo '<pre>';print_r($result);echo '</pre>';
function generateHash($timestamp, $domain, $nonce, $api_key, $method_name)
{
$hash = hash_hmac('sha256', $timestamp .';'. $domain .';'. $nonce .';'. $method_name, $api_key);
return $hash;
}
function createRandomString() {
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
?>