bigcommerce-api-php icon indicating copy to clipboard operation
bigcommerce-api-php copied to clipboard

Inserting Product images

Open eMatsiyana opened this issue 12 years ago • 3 comments

I have been trying to upload Product images through the API without Success. The Code below states that, the images field can not be writen to and i get the 400 error..

$fields = array( "product_id" => "$prodid", "images" => array("image_file" => "$image")); $apiresult=BigCommerce_Api::updateProduct($prodid, $fields);

So i tried the code below.

$image = new Bigcommerce_Api_ProductImage(); $image->product_id = $prodid; $image->image_file = $image; // etc.. $image->create();

Which then says the Class 'ProductImage' not found.

Is this a namespace issue?

eMatsiyana avatar Nov 20 '13 10:11 eMatsiyana

This is completely untested, but try adding this to a line at the top of your PHP file:

use Bigcommerce\Api\Resource\ProductImage as ProductImage;

zackkatz avatar Feb 11 '14 00:02 zackkatz

Whats the correct way to upload/insert images to product. Is possible through this api???

caovillanueva avatar Apr 25 '14 16:04 caovillanueva

$image = $fields["images"]; BigCommerce_Api::createResource( '/products/' . $productId . '/images', $image );

As per the API, images, among other properties, are Read Only, and cannot be created with the Product Resource. You simply need to specify these Read-Only Resources as their own API calls.

acidburner avatar Apr 20 '17 21:04 acidburner