2016-08-15 113 views
2

我正在嘗試在BigCommerce中執行一個簡單的API調用。 我從這些鏈接的一些信息:BigCommerce API調用 - 獲取訂單

Get a Count of Orders

BigCommerce API Quickstarts

我試過orders.json和訂單/計數,但我沒有得到任何迴應。 我必須錯過簡單的東西。我必須以某種方式迴應回覆嗎?

這是我的代碼。

<?php 

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

?> 

回答

1

我收到了BigCommerce的回覆,它沒有任何幫助。

我在「how to use basic authorization in php curl」,「JSON to PHP Using json_decode」和「JSON」的幫助下解決了這個問題。

我在運行PHP 5.6.22和curl 7.36.0的GoDaddy託管服務器上的.php文件中運行此代碼。

<?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 

?>