Error creating product via API for certain products

New Member
13 0 0

I am experiencing weird issue when creating certain products. I am using c# HttpClient for posting requests and for certain products I just get a 502 bad gateway error. The page says "There was a problem loading this website Try refreshing the page. If the site still doesn't load, please try again in a few minutes.". When I save the json generated via the same code to a file and then read the string from there, it works ok. But if I convert the object to json from code and send a request, it doesn't work. Also, as shown on Fiddler, the request seems ok but it returns an error. However, if i replay that request from Fiddler, the product is created ok. 

If it helps, here's a request ID for the product creation via API that returned an error.
X-Request-ID: a1c87734-eb14-4ffe-8431-05950d48632b

Here's the JSON Payload for the product https://pastebin.com/9SKFPjGJ
This works ok when read from a file but when converted from object to json string(with the same code used to generate the json in that pastebin link) and used directly, it doesn't work.

I have spent the last 2 days trying to get this to work but to no avail so any help would be greatly appreciated. 

thanks

0 Likes
Highlighted
Shopify Staff
Shopify Staff
106 20 22

Hey @My_Pap_Shopify_ ,

 

Going through our log files for the request ID "a1c87734-eb14-4ffe-8431-05950d48632b" it appears that this POST request fails because to the job to create the product in your store is taking too long, and it exceeds the timeout.

 

Assuming you are using the same payload for all of your requests, I am not sure why your create product POST request succeeds when read from a file but timesout when converted to a JSON string. Could you perhaps share the X-Request-ID of the successful request, so I can compare what may be different between the two? Alternatively, you could also try to create a new smaller product with fewer variants and images via the failing JSON string method and see if the POST request fails or not - this way we could isolate if the problem to being either caused by the JSON string method somehow or if the timeout problem is caused by the product creation request being too large. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
13 0 0

Hi Hassain,
Sorry I just saw your reply. 
The normal code works ok for most products, it just gives this error for some products. Yes I have noticed it working for products with smaller variants and even for products with lots of variants and images. But sometimes, it even fails for products with smaller variants. Strange thing is I even tried debugging the request in fiddler and from the code, it shows as failed in fiddler. But when i replay that same request from fiddler, it works ok.

Here is the request ID for the successful request with the full payload 

x-request-id →94938d09-c750-437d-ac8c-20cf142c9aef

Please note that the GUID part of the image URLs in the json payload are different in the two requests but they essentially point to the same image
ie the bold part in this image url https://ae01.alicdn.com/kf/HTB1qKCGXh_rK1RkHFqDq6yJAFXaj/43b349da-a4f0-4b1f-9c14-0c7050622bb3.jpg
Please let me know if you have any questions.

I have been scratching my head over this for more than 3 days now so really look forward to getting it resolved :)

thanks

0 Likes
Shopify Staff
Shopify Staff
106 20 22

Hi @My_Pap_Shopify_ ,

 

Thank you for the new Request-ID, and all of the additional context you provided. It is good to know that the normal code works for most products, it is only in some cases you are getting the Status 502 errors.

 

When comparing the logs of the successful request to the failing request, I could verify that the payload and headers of the two requests were very similar. However when deep diving into the logs, the biggest difference between these two requests I could find was that in the failing request it took Shopify significantly more time to download the image files  from the https://ae01.alicdn.com domain (i.e. for the successful request Shopify could download each image in approximately ~0.1s whereas in the failing request each image took approximately ~1.5s to download). It is most likely due to the longer download times of images from the https://ae01.alicdn.com domain that caused the failing request to completely timeout. I am not sure at all why Shopify would take more time to download the images in some cases and not others, especially if the images are the same file and size - it could be ae01.alicdn.com throttling traffic, or Shopify under heavier load at the time, or other reasons.  

 

In terms of potential solutions here, perhaps you could break your requests up so you separate creating the Product and Variants from the uploading of the images. For example, first send a POST request to just create the Product and all of its Variants, and then afterwards sent PUT requests to upload images for these created Variants. This would decrease the size of your requests and how much time it will take Shopify to process your requests, which will make it less likely for your requests to timeout and fail. Alternatively, you could also just try to re-sending your requests every time they timeout until they eventually succeed. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
13 0 0

Hi Hassain,
Yes exactly, the images are both same, just the GUID is different for identification but it can be replaced with anything and would open the same image.
For now, I have broken the request into multiple parts as you have said, by first just creating variants and sending images in another request. This has been working well and the problem seems to be resolved for now.

 

Thanks for your help!

 

 

0 Likes