2

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.

<?php

curl --request GET \
  -u "username:key" \
  https://store.com/api/v2/orders/count;

?>
newb
  • 115
  • 11

1 Answers1

1

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.

<?php

$username = "Username";
$password = "API Token";
$URL = "https://store.com/api/v2/orders/count.json";

$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_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

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

$response = curl_exec($ch);

curl_close($ch);

$result = json_decode($response);

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

?>
Community
  • 1
  • 1
newb
  • 115
  • 11