简体   繁体   中英

What is more required to work with your Big commerce API except cUrl?

Hi i have written this below code to work with bigcommerce API . But it seems it have some server issue . My server is PHP >5.3 & curl enabled but API seems is not returning any response . Can any one help me how to solve that issue ?

Here is my code

    $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, 'https://store-bwvr466.mybigcommerce.com/api/v2'); 
    curl_setopt($ch, CURLOPT_USERPWD, 'demo'.':'.'df38dd10e9665a3cfa667817d78ec91ee9384bc3');
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); 

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));

    $result = curl_exec($ch); 

    curl_close($ch);

 echo "<textarea>".$result."</textarea>";

 phpinfo();

You can check it into my live server http://fuzonmedia.com/big/server_test.php

Thanks

All requests to the Bigcommerce API need to be encrypted using the SSL_RSA_WITH_RC4_128_SHA cipher. Most initial problems with the API are due to not telling cURL to use the correct cipher when sending a request. As your system is using the NSS library to handle the encrypting you can tell cURL which cipher to use with the following line of code.

    curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'rsa_rc4_128_sha');

If this doesn't solve your issue you will need to check to see if cURL is returning any errors. You can do this by modifying your code as follows.

    $result = curl_exec($ch); 
    if ($result === false) {
        echo '<textarea>'.curl_error($ch).'</textarea>'; 
    } else {
        echo "<textarea>".$result."</textarea>";
    }
    curl_close($ch);

Outputting the error message may give you more clues as to what is going wrong. You can also obtain more information by switching on the verbose option. Note that this information is outputted to STDERR so you will not see it on your web page unless you redirect STDERR to STDOUT , ie the browser window.

    // Switch on verbose information and display it on the web page.
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+'));

Hope the above helps.

Kind Regards,
David

Following up from the previous answer - You can also use the Bigcommerce PHP library ( https://github.com/bigcommerce/bigcommerce-api-php ) which provides an easier way to interact with the APIs using PHP. You can access products like -

require 'vendor/autoload.php';
use Bigcommerce\Api\Client as Bigcommerce;
$products = Bigcommerce::getProducts();

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

Regards to David's answer about cipher, you need to set it to rsa_rc4_128_sha, similar to following. Hopefully this helps. -

Bigcommerce::configure(array(
'store_url' => 'https://store-xxx.mybigcommerce.com',
'username' => 'admin',
'api_key' => 'xxxxxx'
));
Bigcommerce_Api::setCipher('rsa_rc4_128_sha')
Bigcommerce_Api::verifyPeer(false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM