I need a little help regarding to BigCommerce API. I wanted to ask that how can I write this statement

GET orders/{id}/products.json

in php.

Basically I am trying to get products from a specific order. IF I type it in command prompt it returns me the products in the shel but i wanna run it in php.

Any ideas?

Let me know thanks.

有帮助吗?

解决方案

You can make a cURL request to BigCommerce Products API

Following is a simple cURL snippet to get products details:

<?php 
$api_url = 'https://XYZ.mybigcommerce.com/api/v2/orders/201/products.json';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );
curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, "admin:YOUR API KEY" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

$response = curl_exec( $ch );

$result = json_decode($response);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top