$Product->images[], potentially useful but pratically not

Good day.

Just to point out that the potentially useful $Product->images array, which allows devs to alter images employing a single REST call, cannot actually be used in practice as all (possible) warning/errors are suppressed whereas updating each Image entity singularly correctly returns errors.

// Updating images via $Product, errors are suppressed

Product->Images = [

[ “src” => “bogus URI…” ],

[ “src” => “legit URI…”]

];

// Updating images via $Image, errors are returned

Image->product_id = 111111111;

Image->src=“bogus URI…”;

Hi @sexybit :waving_hand:

Thanks for your feedback! Would you please confirm that you’re referring to the Shopify API PHP library, and I can certainly let the team know. Keep in mind, you can also submit issues in the repo directly.

Good day.

Yes, I’m using the PHP library in question but I highly doubt the issue is specific to the library.

A different library is likely to produce the same results.

This is an issue of the API itself which doesn’t execute the update of the main entity (“Product”) and the related entities (“Images”) atomically, i.e. it all succeeds or it all fails.

Thanks.

Thanks for confirming that!

Using the REST API with curl requests, updating products with 2 images (one invalid url , one valid url) results in just the valid url being added as an image object. As you mentioned, there aren’t any errors returned to indicate that one source was invalid however.

curl -L -X PUT 'https://STORE-NAME.myshopify.com/admin/api/2022-10/products/6767605612662.json' \
-H 'X-Shopify-Access-Token: ADMIN-TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{"product": {"id": 6767605612662,"images": [{"src": "https://upload.wikimedia.org/wikipedia/commons/f/ff/Cat_in_home.jpg"},{"src": "https://this-is-some-invalid-image-url-for-testing"}]}}'

Does the above fail to create the one valid image for you?

I could be wrong but I sense you’re missing the point.

The point is not whether “the above fails to create the one valid image”.

The point is that if one entity (the image in this case) cannot be created for whatever reason, an error should be returned and the entire action (the creation of a Product) should fail.

Until that is fixed, the very convenient $Product->images array is useless.

Thanks for clarifying!

I’ll be sure to let the product team know that it would be more valuable to have the entire action fail with a 400 Bad Request, since having only the valid images of the array created is useless to you.

Again, this is not about the validity of the image URL per se. I just picked that one as an example.

There could be all sorts of errors, eg. a timeout while trying to fetch the URL.

This is about returning errors and having the entire action (the creation of Product) fail when part of the entire job cannot be carried out successfully - for whatever reason.

If memory serves me well, trying to create the image as a standalone entity returns a 422 Unprocessable entity response.