Adding another image to a product PHP API

Drive_Computing
Shopify Partner
8 0 0

Have been able to upload an image (by URL) to my product.
However when trying to add an additional image it over writes the previous image.

This is the code that is used to upload an image.

$baseUrl = 'https://xxxxxx:xxxxxx@drive-computing-store.myshopify.com/admin/';
set_time_limit(0);
$headers = get_headers($baseUrl . 'shop.json', 1);
$apiLimit = (int) str_replace('/500', '', $headers['HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT']);  

$product = array(
        "id" => "xxxxxx",
        "images" => array(
            array(
                "src" => "$imageURL"
            )),
    );

    $ch3 = curl_init($baseUrl . 'products/' . $productID . '.json');  //note product ID in url
    $data_string3 = json_encode(array('product' => $product)); //json encode the product arrayprint_r($data_string);
    curl_setopt($ch3, CURLOPT_CUSTOMREQUEST, "PUT");  //specify the PUT verb for update
    curl_setopt($ch3, CURLOPT_POSTFIELDS, $data_string3);  //add the data string for the request
    curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true); //set return as string true
    curl_setopt($ch3, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string3)
    )); //set the header as JSON
    curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
    $server_output3 = curl_exec($ch3); //execute and store server output
    if (curl_errno($ch3)) {
        print curl_error($ch3);
    }
    curl_close($ch3); //close the connection

Any help would be appreciated.

 

0 Likes
deliberti
New Member
1 0 0

POST OR PUT?

0 Likes