Noobie bigcommerce API connection

前端 未结 5 1898
粉色の甜心
粉色の甜心 2021-01-22 22:21

Sorry for the noobie question but I just wanted to know the process by which I could at least connect to my bigcommerce store and query it via a PHP or curl script.

If s

相关标签:
5条回答
  • 2021-01-22 22:58

    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

    0 讨论(0)
  • 2021-01-22 22:59

    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!

    0 讨论(0)
  • 2021-01-22 23:00

    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.

    0 讨论(0)
  • 2021-01-22 23:05

    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.

    0 讨论(0)
  • 2021-01-22 23:08

    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.

    0 讨论(0)
提交回复
热议问题