A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
I'm getting 502 Bad Gateway error when trying to create a product with 30+ variants using GraphQL. This is not the case if I create a product with fewer variants.
Looking in other cases it looks like it is a common problem, but I didn't found any way to solve this.
Any idea/recommendation?
Thanks.
Solved! Go to the solution
This is an accepted solution.
Hi.
After a while doing some test and researching, we finally had to adjust or code to:
1. First, create the product with his variants using productCreate mutation.
2. Then, upload all media files (images) to the product and assign images to each variant.
After that, we have not experienced 502 Bad Gateway errors anymore.
It looks like Shopify have troubles handling mutations with too many variants/images.
Hey @chescko29
By any chance would you have the request_id from that failing request? I can take a look into it for you. Thanks!
This is an accepted solution.
Hi.
After a while doing some test and researching, we finally had to adjust or code to:
1. First, create the product with his variants using productCreate mutation.
2. Then, upload all media files (images) to the product and assign images to each variant.
After that, we have not experienced 502 Bad Gateway errors anymore.
It looks like Shopify have troubles handling mutations with too many variants/images.
Hello thanks for sharing, right now I am experiencing the same error, could you help me with an example of the code that you used to solve this problem?
Hi.
This is a common issue. When you try to create a product including all images and all variants in a single productCreate mutation it looks like the size of the query is too big, so you get the 502 error.
So, I solved this by separating the product creation into multiple steps programmatically, which requieres more code but is more efficient.
I can't share examples of code but I can give you some steps to follow.
1. First, create the product with his variants using productCreate mutation. (Just create the product and variants with no images.) https://shopify.dev/docs/api/admin-graphql/2022-10/mutations/productcreate
2. Then, upload all media files (images) to the product. You should use stagedUploadsCreate mutation https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/stageduploadscreate and productAppendImages https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/productAppendImages
3. Finally assign images to variants using productvariantupdate mutation https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/productvariantupdate
This is the way Shopify recommends to upload media. You can check this link for mor info https://shopify.dev/docs/apps/online-store/media/products
Thank you very much for the information, I will put it into practice!