Trend Snaps
Trend Snaps

Reputation: 198

product image is not inserting to shopify store Via API

I am trying to insert product to my Shopify store using Shopify Product API .

Now i can insert the product data as well as variants of the products .

here is my script

<?php

  $name='test product 999';
  $group=36;
  $quantity=20;
  $price='20.95';
  $image = "http://clarks.scene7.com/is/image/clarks/26103666_A";

  $url = "https://xxx:[email protected]/admin/products.json";

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  $type = 'POST';
   $product = array('title' => utf8_encode($name),
    'body_html' => utf8_encode($name),
    'product_type'=> $group,
    'vendor'=>'abc',
    'id'=> '999',
    "tags" => "Emotive, Flash Memory, MP3, Music",
    "images"=>array     ("src"=>'http://clarks.scene7.com/is/image/clarks/26103666_A'),
    'variants' => array(
    array('price' => $price,
        'compare_at_price'=> $price,
        'sku'=>'123gdjf',
    'inventory_quantity'=> $quantity,
    'inventory_management' => 'shopify'
    )
    )

    );

      $ch = curl_init($url);
      $data_string = json_encode(array('product'=>$product));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
    );

     $server_output = curl_exec ($ch);
     print_r($server_output);
       curl_close ($ch);


     ?>

No images are storing only product data is storing . can any one let me know where i am wrong . or whats wrong in my script .?

thank you

Upvotes: 1

Views: 471

Answers (1)

Trend Snaps
Trend Snaps

Reputation: 198

sorry ..

there was very small mistake .

i have replaced code

"images"=>array     ("src"=>'http://clarks.scene7.com/is/image/clarks/26103666_A'),

With

"images"=>array( array ("src"=>'http://clarks.scene7.com/is/image/clarks/26103666_A')),

Now my images are storing

thanks

Upvotes: 1

Related Questions