Zetaphor
Zetaphor

Reputation: 504

Bigcommerce PHP API - No data returned

I'm using the single file PHP library. I've got the store connecting, but I am getting no data back. Here is my script:

<?php
error_reporting(E_ALL);
ini_set('display_errors', True);
 require 'bigcommerce.php';
    use Bigcommerce\Api\Client as Bigcommerce;

    $settings = array('store_url' => 'https://STORE_URL_REDACTED.mybigcommerce.com','username' => 'USERNAME_REDACTED', 'api_key' => 'API_KEY_REDACTED');

    if( 
        (array_key_exists('store_url', (array)$settings)) &&
        (array_key_exists('username', $settings)) && 
        (array_key_exists('api_key', $settings)) 
    ) {
        // Config Basic
        Bigcommerce::configure(
            array(
                'store_url' => $settings['store_url'],
                'username'  => $settings['username'],
                'api_key'   => $settings['api_key']
            )
        );
        Bigcommerce::setCipher('RC4-SHA');
        Bigcommerce::verifyPeer(false);
    }    

$products = Bigcommerce::getProducts();

$orders = Bigcommerce::getOrders();

foreach($products as $product) {
    echo $product->name;
    echo $product->price;
}
?>

I've got output writing on the curl commands in bigcommerce.php, and I can see that I am actually connecting to the store:

I get the following error:

Warning: Invalid argument supplied for foreach() in /home/zetaphor/public_html/bigcommerce-api-php-master/coupons.php

My returned arrays contain no data.

I am running a LAMP stack using PHP 5.3.3, cURL enabled

Upvotes: 0

Views: 1123

Answers (2)

Aamir Satti
Aamir Satti

Reputation: 48

I was facing that problem in php class, so i have done this using CURL, You can get your stores products, orders and coupon.

here is the code.

    $username = 'your username'; 
    $password = 'your key';
    $url = ' your store url';
    $product_url = $url.'/api/v2/products.json';

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $product_url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_ENCODING, "");
    $curlData = curl_exec($curl);
    curl_close($curl);
    //returning retrieved feed

    $product_rec  = json_decode($curlData);
    echo '<pre>';
    print_r($product_rec);

now for orders use

    $order_url =  $url.'/api/v2/orders.json'; 

Upvotes: 1

developerscott
developerscott

Reputation: 923

There is normally another line below the setCipher line to "verify peer". Try adding that in so that it would look like:

Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

Edit: to be clear, I think this is a key piece for the server to check that your certificate is valid.

Upvotes: 0

Related Questions