Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Product images disappear sometimes after bulk update operation

Iceshop
Shopify Partner
2 0 0

We use GraphQL Admin API for updating products in bulk, using productUpdate and bulkOperationRunMutation.

Normally all works fine, but sometimes images disappear for some products after such update, with no error message.
It happens when we send images ids after changing their order. So no new images urls, just ids of existing images in new order.
Bulk operation example:

mutation {
            bulkOperationRunMutation(
            mutation: "mutation call($input: ProductInput!) { productUpdate(input: $input) { product {id} userErrors { message field } } }",
            stagedUploadPath: "tmp/61844521178/bulk/f739b254-0406-4555-af4a-c65b8810323c/shopify_update_products.json") {
                bulkOperation {
                    id
                    url
                    status
                }
                userErrors {
                    message
                    field
                }
            }
         }

shopify_update_products.json contains rows like these:

{"input":{"id":"gid:\/\/shopify\/Product\/7687249035482","images":[{"id":"gid:\/\/shopify\/ProductImage\/40047562522842"},{"id":"gid:\/\/shopify\/ProductImage\/40057898893530"},{"id":"gid:\/\/shopify\/ProductImage\/40057898827994"},{"id":"gid:\/\/shopify\/ProductImage\/40047562588378"},{"id":"gid:\/\/shopify\/ProductImage\/40047562555610"},{"id":"gid:\/\/shopify\/ProductImage\/40047562621146"},{"id":"gid:\/\/shopify\/ProductImage\/40057898795226"},{"id":"gid:\/\/shopify\/ProductImage\/40047562653914"},{"id":"gid:\/\/shopify\/ProductImage\/40057898860762"},{"id":"gid:\/\/shopify\/ProductImage\/40057898762458"}]}}
{"input":{"id":"gid:\/\/shopify\/Product\/7687250215130","images":[{"id":"gid:\/\/shopify\/ProductImage\/40463199404250"},{"id":"gid:\/\/shopify\/ProductImage\/40463199437018"},{"id":"gid:\/\/shopify\/ProductImage\/40463199469786"},{"id":"gid:\/\/shopify\/ProductImage\/40463199502554"},{"id":"gid:\/\/shopify\/ProductImage\/40463199535322"},{"id":"gid:\/\/shopify\/ProductImage\/40463212871898"},{"id":"gid:\/\/shopify\/ProductImage\/40463212904666"},{"id":"gid:\/\/shopify\/ProductImage\/40463212937434"},{"id":"gid:\/\/shopify\/ProductImage\/40463212970202"},{"id":"gid:\/\/shopify\/ProductImage\/40463213002970"},{"id":"gid:\/\/shopify\/ProductImage\/40463534588122"},{"id":"gid:\/\/shopify\/ProductImage\/40463534620890"},{"id":"gid:\/\/shopify\/ProductImage\/40463534653658"},{"id":"gid:\/\/shopify\/ProductImage\/40463534686426"},{"id":"gid:\/\/shopify\/ProductImage\/40463534719194"},{"id":"gid:\/\/shopify\/ProductImage\/40463779037402"},{"id":"gid:\/\/shopify\/ProductImage\/40463779070170"},{"id":"gid:\/\/shopify\/ProductImage\/40463779102938"},{"id":"gid:\/\/shopify\/ProductImage\/40463779135706"},{"id":"gid:\/\/shopify\/ProductImage\/40463779168474"}]}}
{"input":{"id":"gid:\/\/shopify\/Product\/7687250641114","images":[{"id":"gid:\/\/shopify\/ProductImage\/40237366051034"},{"id":"gid:\/\/shopify\/ProductImage\/40237366083802"},{"id":"gid:\/\/shopify\/ProductImage\/40237366116570"},{"id":"gid:\/\/shopify\/ProductImage\/40237366149338"},{"id":"gid:\/\/shopify\/ProductImage\/40237366182106"},{"id":"gid:\/\/shopify\/ProductImage\/40242900467930"},{"id":"gid:\/\/shopify\/ProductImage\/40242900500698"},{"id":"gid:\/\/shopify\/ProductImage\/40242900533466"},{"id":"gid:\/\/shopify\/ProductImage\/40242900566234"},{"id":"gid:\/\/shopify\/ProductImage\/40242900599002"},{"id":"gid:\/\/shopify\/ProductImage\/40242968494298"},{"id":"gid:\/\/shopify\/ProductImage\/40242968527066"},{"id":"gid:\/\/shopify\/ProductImage\/40242968559834"},{"id":"gid:\/\/shopify\/ProductImage\/40242968592602"},{"id":"gid:\/\/shopify\/ProductImage\/40242968625370"},{"id":"gid:\/\/shopify\/ProductImage\/40246756671706"},{"id":"gid:\/\/shopify\/ProductImage\/40246756704474"}]}}

The results of the bulk operation is successful:

 

 

{"data":{"productUpdate":{"product":{"id":"gid:\/\/shopify\/Product\/7687249035482"},"userErrors":[]}},"__lineNumber":0}
{"data":{"productUpdate":{"product":{"id":"gid:\/\/shopify\/Product\/7687250215130"},"userErrors":[]}},"__lineNumber":1}
{"data":{"productUpdate":{"product":{"id":"gid:\/\/shopify\/Product\/7687250641114"},"userErrors":[]}},"__lineNumber":2}

But actually some products may lose their images.
Usually it doesn't happen, but sometimes it happens with some of the updated products.

 

What could be the cause?

 

Replies 3 (3)

Liam
Shopify Staff
2677 288 737

Hi Iceshop - this does sound unusual, I've reached out to our internal team to see what might be causing this. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Liam
Shopify Staff
2677 288 737

Hi again - our API support have advised using the task-specific productReorderMedia mutation instead. This mutation runs as an asynchronous job (kind of like a self contained bulk operation) and is designed just for re-ordering media so should be most reliable for the task. Would this work for your use-case?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Iceshop
Shopify Partner
2 0 0

Hi Liam,

 

Thanks for the suggestion. We will check if productReorderMedia helps.