Ad

Add Product Images With Shopify API

- 1 answer

We have a bunch of disassociated product images in our Shopify store that support could not re-associate. I set up a Postman collection runner to update all these missing images, and it seems to be working in our test environment....

Except, the API call is replacing the default product image with a new image rather than adding the image. I'm using a standard PUT request to the API using the example in their API docs:

PUT /admin/api/2019-04/products/#{product_id}.json

 {
  "product": {
    "id": 632910392,
    "images": [
      {
        "src": "http://example.com/rails_logo.gif"
      }
    ]
  }
}

I get that it's an array I'm sending in, so I'm thinking it's overwriting the array each time rather than adding a new element. I tried using a single element variable of "image" in the JSON but that didn't work.

Any ideas?

Ad

Answer

If you want to add the image use ProductImage resource instead of Product resource.

Product Image Documentation

POST /admin/api/2019-04/products/#{product_id}/images.json
{
  "image": {
    "src": "http://example.com/rails_logo.gif"
  }
}
Ad
source: stackoverflow.com
Ad