user2721270
user2721270

Reputation: 59

How to add images for a product in bigcommerce by API

How can I add images to a product through Bigcommerce API. The images will be sent at the time of CreateInventory API or after inventory creation image will be added by CreateImage API by using created product id and give me sample request json format if possible.

Upvotes: 5

Views: 1816

Answers (2)

Dan
Dan

Reputation: 9468

As per this issue: https://github.com/bigcommerce/api/issues/67 the Bigcommerce API does not currently support adding an image during the creation of a product. So creating a product with an image requires two POST requests.

First POST to

`https://api.bigcommerce.com/stores/{{store_id}}/v3/catalog/products`

Sample body:

{  
   "name":"Super Duper Product",
   "price":20,
   "categories":[23],
   "type":"physical",
   "is_visible":true,
   "weight":"16",
   "inventory_level":0,
   "product":{  
      "variants":[  
         {  
            "price":20,
            "weight":"16",
            "inventory_level":0,
            "sku":"27561248",
            "option_values":[]
         }
      ]
   }
}

Then POST to https://api.bigcommerce.com/stores/{{store_id}}/v3/catalog/products/{{product_id}}/images

Sample body:

{
  "is_thumbnail": true,
  "image_url": "https://www.test.com/image.jpg",
}

An additional call is needed for each additional image, only one image can be set as the thumbnail.

Upvotes: 2

Anakbhai Gida
Anakbhai Gida

Reputation: 668

Hello dear you need do something like below first connect with api

    require_once'(Api.php');
    Big Commerce Default Api Setting
    Bigcommerce_Api::configure(array('store_url' => 'store url','username'  => 'username','api_key'   => 'apikey',));
    BigCommerce_Api::verifyPeer(false);
    Bigcommerce_Api::setCipher('RC4-SHA');
    Bigcommerce_Api::failOnError(true);

after configuration you need to do this

        $new_product_image = new Bigcommerce_Api_ProductImage();
        $new_product_image->product_id      = $bid;
        $new_product_image->image_file      = $img_url;
        $new_product_image->is_thumbnail    = true;
        $new_product_image->description     = "";
        $product_image = $new_product_image->create();

here need to pass the big commerce product id and image url where your image is located set is_thumbnail = true for main image than call the create method of api

Upvotes: 3

Related Questions