integrating php with bigcommerce api

允我心安 提交于 2019-12-05 21:47:29
Jay

Apparently i had no idea Big-commerce doesn't need me to host any server code on their side or whatever, i found out that which ever code i write is simply run on my side so i can interact with my store. i wonder why i couldn't really find this information anywhere easily, shouldn't it be the first thing we see when we reach the developers page on bigcommerce.com??

Anyway, i found what i was looking for and i understand how it works now.

To begin, as far as where do your PHP scripts go, those will be hosted external to your Bigcommerce store from any server that has PHP installed or from your local computer. The Bigcommerce API basically gives you a way to access and make changes to your store's database using a program. You will interact with API resources endpoints (URLs) which have been tied to specific store related data, like your products or orders. You can make GET, PUT, POST, and DELETE requests on these URLs in order to pull, modify, create, or delete store related data, respectively. the php files are here https://github.com/bigcommerce/bigcommerce-api-php , and these should be in your machine with a PHP server to get started there are sample codes there also.

i had problems with this line

require 'vendor/autoload.php';

so i changed it to

require 'path_to_this_file/bigcommerce.php';

everything is working fine now... but iam still learning more

Chirag B

Have a look at this Link for the list of Resources.

Your php file will be making calls to BigCommerce API, to get data from BigCommerce Store.

Simple cURL snippet to get orders.

$api_url = 'https://YOUR-API-PATH.mybigcommerce.com/api/v2/orders.json';
$ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); 
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );                                   
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); 
curl_setopt( $ch, CURLOPT_USERPWD, "YOUR-USERNAME:YOUR-API-TOKEN" ); 
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );   
$response = curl_exec( $ch );   
$result = json_decode($response); 
print_r($result);

Hope this helps.

For that you can not make directly call to your store front..for that make request from third party server to get your store Api.

call bellow php code by Ajax request...

like that..

----------Php Code:-

$username='username';//API User name
$password='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//API Token
$URL='https://store-xxxxxxx.mybigcommerce.com/api/v2/products';//API path

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:UTF-8','Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  code
$result=curl_exec ($ch);
curl_close ($ch); 
print_r($result);//Your Requested Data
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!