Update Image src without ID changing

Highlighted
New Member
2 0 1

Hi,

 

I seem to be having problems with image updates on a product in the API. If I update a products image for an image that already exists for example (it can be the same image with a new file name or a new image entirely), it uploads it no problem in place of the existing one, however the ID number changes:

 

{
  "product": {
    "id": 0000000001,
    "images": [
      {
        "id": 0000000002,
        "src": "newimage.jpg"
      }
    ]
  }
}

 

Can anyone please let me know why ID numbers are changing. The problem is if software using the API is relying on the image ID as a reference and it changes at times it shouldn't then that software will break.

 

It would make sense for the ID number to not change. The ID number should be for the image objects existence and not be affected by the properties of it changing. A perfect example is in the case where I update with an image that is exactly the same just with a different filename there is no reason for the ID number to change.

 

If there is a way to avoid ID numbers of the images changing and still updating their source I would love to know. 

 

Thanks

:)

 

 

0 Likes
Highlighted
Shopify Partner
1777 211 370

One should never rely on IDs for any of the Shopify objects, these are internal IDs used by Shopify to uniquely identify an entity, even across stores. This is why when you say you are updating an image, actually you are creating a new image object.

 

Though I would love to have one another field that can be populated at the time the image is created and then used to get the image, what you are left with is, either you encode your specific image id in the image name, or use for example the alt field at the image object level for that purposes.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Excursionist
40 1 6

This is a real shame, product- images need to support metafields really, then I could use that

 

At the moment everytime I update a product I push new images that then get new IDs. It makes it difficult to not only update the images, but also to be able to relate a variant to an uploaded image.  The only way I can think of doing this is through the altText, but that really doesn't feel right

 

Actually, looks like you can't update an image with the id in product update, I got this when I gave the ID and the src of teh image

"message""Either specify id to reference an existing image, or src to add new image to product. Do not specify both.",

 

Probably need to use this: productImageUpdate  and remove the images:[] part

 

You would then update the images that needed updating

 

I am not sure how yo would add new images though

 

Thanks

 

Grant

0 Likes