Ad

Shopify Api Post Multiple Variant Images On One Call

- 1 answer

I'm trying to post to shopify via the api multiple image/variants at once. I'm currently using guzzle php and this works:

  $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

However I need to do multiple ones so I'm trying to do something like this:

 $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ],
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

The above does not work. Neither does this work:

 $response = $shop->api()->rest('POST', '/admin/products/#{productnumber}/images.json' ,[
  "image" => [
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"],
    "src" => "https://example.com/images/blahblah.jpg",
    "variant_ids" => ["9999999999"]
  ]

I can loop over each image and variant but I'm trying to avoid having to make multiple calls. Let me know please. Thank you!

Ad

Answer

I think you would have to use GraphQL and try the mutation there to add an array of images. The RestAPI is a one-trick pony it seems with one call per image. I looked through all my old codes and always burned an API call per image.

GraphQL has the concept of images[] though, so that is your best bet it seems.

Ad
source: stackoverflow.com
Ad