Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The following examples uses file_get_contents(), which is supported by PHP natively. You may also use curl, but you need to install it on your server first.
Listing all Inventory for initial data load
<?php
$data = array('key' => 'YOUR API KEY', 'includeItemsWithQuantityZero' => false);
 
$context = stream_context_create(array(
	'http' => array(
		'method' => "GET",
		'header' => "Accept: application/json\r\n".
					"Content-Type: application/json\r\n",
		'content' => $data_string
	)
));
 
$result = file_get_contents('http://user.traxia.com/app/api/inventory', false, $context);
var_dump($result);
?>

 

 

Listing changes in inventory based on a unix timestamp
<?php
$modifiedSince = strtotime('07/28/2014 6:10 GMT') * 1000;
$data = array('key' => 'YOUR API KEY', 'modifiedSince' => $modifiedSince, 'includeInactiveItems' => true);
 
$context = stream_context_create(array(
	'http' => array(
		'method' => "GET",
		'header' => "Accept: application/json\r\n".
					"Content-Type: application/json\r\n",
		'content' => $data_string
	)
));
 
$result = file_get_contents('http://user.traxia.com/app/api/inventory', false, $context);

var_dump($result);
?>

Don't forget to parse $http_response_header

 This StackOverflow answer gives an example of the output of $http_response_header. You should look for or parse for the "200" HTTP status code, or alternatively use php's error_get_last() to see if file_get_contents threw an error.

Error handling
<?php
 
//Call after file_get_contents
 
$lastError = error_get_last();
if (is_null($lastError)) {
	// file_get_contents worked successfully
} else {
	// We failed, see the contents of the error
	var_dump($lastError);
}
 
?>

Other Helpful PHP Resources

 

  • No labels