Matt Matt - 2 months ago 17x
PHP Question

BigCommerce API Call - Get Orders

I'm trying to do a simple API call in BigCommerce.
I got some info from these links:

Get a Count of Orders

BigCommerce API Quickstarts

I've tried orders.json and orders/count, but I do not get any response.
I must be missing something simple. Do I have to echo the response somehow?

Here is my code.


curl --request GET \
-u "username:key" \;



I received a reply from BigCommerce and it was no help.

I figured this out with the help of "how to use basic authorization in php curl", "JSON to PHP Using json_decode", and "JSON".

I ran this code, in a .php file, on a GoDaddy hosted server running PHP 5.6.22 and cURL 7.36.0.


$username = "Username";
$password = "API Token";
$URL = "";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //Timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Get status code

$response = curl_exec($ch);


$result = json_decode($response);

echo "Count = " . $result->count; //Total orders
echo "<br />" . $result->statuses[8]->name . " = " . $result->statuses[8]->count; //Shipped orders