Noobie bigcommerce API connection

此生再无相见时 提交于 2019-12-02 01:31:46

1) Requirements

    PHP 5.3 or greater
    cUrl extension enabled

2) Create Folder wamp/www/bigcommerceDemo and Download https://github.com/bigcommerce/bigcommerce-api-php/archive/master.zip in it.

3) Install composer with composer install command

4) Create index.php file in bigcommerceDemo folder means your project folder

index.php File :- 


  <?php
    require 'vendor/autoload.php';

    use Bigcommerce\Api\Client as Bigcommerce;

    Bigcommerce::configure(array(

        'store_url' => 'https://xyz-com.mybigcommerce.com/',
        'username' => 'admin',
        'api_key' => 'dummy92f6fd3df7f140719c1889e78d9c026999p'
    ));

    Bigcommerce::verifyPeer(false);

    $ping = Bigcommerce::getTime();

    if ($ping) {
        //echo $ping->format('H:i:s');
    }
    Bigcommerce::failOnError();

    try {
        $orders = Bigcommerce::getOrders();

    } catch(Bigcommerce\Api\Error $error) {
        echo $error->getCode();
        echo $error->getMessage();
    }

    $products = Bigcommerce::getProducts();

    //echo '<pre>'; print_r($products); exit;

    echo '<pre>';

    foreach($products as $product) {
        //print_r($product);
        echo $product->name . '---------';
        //echo $product->price . '<br>';
    }

5) Run localhost/bigcommerceDemo : This file display all products.

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_VERBOSE, 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

The API documentation is pretty good. The key (which I originally struggled to figure out) is that as a starting place it needs to run on a server.

Install xampp or similar that is running PHP. From there make sure to reference the API file, authenticate, code away. I have found that this was the gap in the documentation.

you can install MAMP on your mac, then proceed to http://developer.bigcommerce.com/ to get your api keys. then just download the Bigcommerce PHP API, see the API Doc to learn to use it.

I wouldn't advise using CURL option... I began this way but highly recommended the PHP API that Bigcommerce have created.

You can find the quickstart documentation @ http://developer.bigcommerce.com/quickstarts/php

If you wanted to do that using PHP API you would only have to write the following...

1.) Install WAMP 2.) Download the PHP API from Github here : https://github.com/bigcommerce/bigcommerce-api-php 3.) Following the instruction on the github page here https://github.com/bigcommerce/bigcommerce-api-php

Ensure that you can 'connect to store' etc and get the correct responses.

If you can't get past this point copy us your code and some errors and will see what we can do!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!