Malformed JSON returned causes json_decode() to throw a JsonException

Using the shopify-api-php library here.

It would appear that, at times, Shopify returns a malformed JSON that causes json_decode() to throw a JsonException (“Syntax error”).

I am now logging these occurrences so I will be attaching X-Request-ID(s), and the relative raw response, as soon as the issue presents itself again.

So far these occurrences have all been caused by InventoryLevel->set() calls.

This is a major nuisance cause the shopify-api-php library simply assumes that the JSON will always be correct hence when the JsonException is thrown our ERP cannot access the JSON hence cannot record locally the outcome of the operation.

Hey there,

I noticed the same thing, and I just repeat the BulkOperation it it fails.

I don’t have much faith that Shopify will fix it, and it doesn’t really happen that often.

Best,

Peter

Appreciate your input, Peter.

since you’re mentioning “BulkOperation”, I’m guessing that this “malformed JSON” issue is not limited to $InventoryLevel->set(). I feared as much.

Also, from your response I seem to gather that you’ve determined that repeating the exact same operation can (eventually) result in a correct JSON. I don’t think that ‘automatically’ retrying the operation would be a good practice as I would be assuming that all malformed JSONs are ‘temporary’ which might not always be the case.

That leaves me with only one option: surfacing the error to the user and have him retry the operation manually which severely undermines user experience.

Have you tried reporting this to support along with X-Request-ID(s)?

If you’re using the PHP library, I’ve opened an issue: https://github.com/Shopify/shopify-api-php/issues/231

Hey there,

yes, in my case, it’s a temporary issue that resolves itself immediately (at the next request).

However, I’m not changing anything, just reading (prices in this case), so I can repeat the request without consequences.

Here’s an example (notice the bolded part):

{“price”:{“currencyCode”:“KMF”,“amount”:“17600.0”},“compareAtPrice”:{“currencyCode”:“KMF”,“amount”:“26200.0{“price”:{“currencyCode”:“KHR”,“amount”:“155000.0”},“compareAtPrice”:{“currencyCode”:“KHR”,“amount”:“230000.0”},”__parentId":“gid://shopify/ProductVariant/42335536349403”}

I haven’t reported this error.

I’ve reported bugs in the past, but Shopify didn’t seem to do anything about them, so I don’t bother with reporting anymore.

Here’s an example that is still not fixed after 2+ years, and it affects prices:

https://community.shopify.com/c/shopify-apis-and-sdks/502-bad-gateway-error-when-retrieving-products-with-presentment/td-p/739184

I’m using my own PHP library, and I wouldn’t hold my breath for Shopify to fix this.

I’d just retry the operation, and before retrying, check the inventory level again to see if it was updated successfully, and then retry (if it wasn’t).

Appreciate you taking the time to share your experience, Peter.