user1260414
user1260414

Reputation: 5

Using cURL to update inventory in BigCommerce

I am using the following code to update products in bigcommerce with new inventory numbers from our Amazon listings - it works perfectly for any product that does not have an option set (specifically gloves and shirts, which obviously have separate inventory levels for each S, M, L).

    $api_url = 'https://store-558hrkjw.mybigcommerce.com/api/v2/products/'.$nearrow['ProductID'].'.json';//put inventory
    $StockdataRAW = array('inventory_level' => 500);//$nearrow['CurrentStockLevel']
    $Stockdata = json_encode($StockdataRAW);
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $api_url );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Content-type: application/json', 'Accept: application/json') );
    curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
    curl_setopt($ch, CURLOPT_POSTFIELDS,     $Stockdata);
    curl_setopt( $ch, CURLOPT_USERPWD, "UID:PW" );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    // 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+'));
    $response = curl_exec( $ch );
    $result = json_decode($response);
    print_r($result);
    $info = curl_getinfo($ch);
    curl_close($ch);

When i use this code for the options i get a 404 for each product id - any thoughts?

Upvotes: 0

Views: 357

Answers (2)

rivimey
rivimey

Reputation: 931

I might be missing something, but it looks like you're not telling the api which option you are referring to, so it can't reply correctly and gives you a 404 as a result.

Upvotes: 0

ShaneOH
ShaneOH

Reputation: 1555

Your code is working for products without option sets because you're hitting the products endpoint, which is used for single products, without option sets/variations.

If you have products with options/variations (such as gloves and shirts), those are going to be SKUs, and you can update those using the SKUs endpoint -- make sure you have the proper id associated with each SKU.

Here are the API docs, which you can reference if you run into any more problems. Note the difference between the Product and SKU objects.

Upvotes: 2

Related Questions