(Bigcommerce API) - add image to existing product

Working with the Bigcommerce API in PHP. Trying to add an image from a url to an existing product. Have tried for a while, but I can't and their documentation doesn't really explain how to properly edit or import product images.

Here's what I have. No luck with that. Any help would be greatly appreciated!

<?php
error_reporting(E_ALL);
ini_set('display_errors', True);

require 'includes/bigcommerce.php';

use Bigcommerce\Api\Client as Bigcommerce;

Bigcommerce::configure(array(
'store_url' => $url,
'username' => $username,
'api_key'   => $key
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

$path = '/product/78/images';
$object = 'http://www.greencoffeelover.com/wp-content/uploads/2015/03/Test-Product.jpg';

Bigcommerce::createResource($path, $object)
?>

      

+3


source to share


2 answers


I figured it out myself.



require 'bigcommerce.php';
use Bigcommerce\Api\Client as Bigcommerce;
use Bigcommerce\Api\Resources\ProductImage as ProductImage;

Bigcommerce::configure(array(
'store_url' => $url,
'username' => $username,
'api_key'   => $key
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

$new_product_image = new ProductImage();
$new_product_image->product_id      = $productID;
$new_product_image->image_file      = $png_url;
$new_product_image->is_thumbnail    = true;
$new_product_image->description     = "";
$product_image = $new_product_image->create();

      

+1


source


You can also use the first way, just change your $ object like this:

$object = array('image_file'=>'http://www.greencoffeelover.com/wp-content/uploads/2015/03/Test-Product.jpg');

      



or use the function createProductImage()

:

$object = array('image_file'=>'http://www.greencoffeelover.com/wp-content/uploads/2015/03/Test-Product.jpg');
Bigcommerce::createProductImage($product_id, $object)

      

0


source







All Articles