A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello. I'm experiencing something very weird, when i try to update a product.
This is a code snippet:
async put(obj) {
try {
const api = this.getApi(obj.webshop);
if (obj.path.includes('products')) {
console.time('Time to update product');
delete obj.data.product.variants;
}
const res = await api.put(obj);
return res;
} catch (e) {
if (e.retryAfter) {
await new Promise((resolve) => setTimeout(resolve, 1000));
return this.put(obj);
}
throw e;
} finally {
if (obj.path.includes('products')) {
console.timeEnd('Time to update product');
}
console.log('\n');
}
}
Where api is an instance of `Shopify.Clients.Rest`
If i include the Variant in the product, my request times out after roughly 80 seconds. However this is not a "normal" timeout, because it fails with an error saying "'Failed to make Shopify HTTP request: FetchError: invalid json response body at https://anotherslegacy.myshopify.com/admin/api/unstable/products/xxxxx.json reason: Unexpected token < in JSON at position 0'", but I'm describing it as a timeout, because it always happens after 80-85 seconds. What I also think is weird is that it seems to be using an "unstable" version..
However it becomes really interesting if i delete variants. ` delete obj.data.product.variants;`Then I can complete al requests within 0.5 - 2 seconds.
It clearly shows in the documentation, that you can update a variant along with a product (https://shopify.dev/api/admin-rest/2022-01/resources/product#put-products-product-id - under "update a product and one of its variants)). And I'm not sending that much data. This is an example of the request:
product: {
body_html: "<p style=\"margin-top:1em\"><strong>Guld Ring i 14 karat</strong></p><p style=\"margin-top:1em\">Vægt: 4.25 gram<br>Stand: Som ses på billeder, god stand med almindelige brugsspor og slidtage</p><p style=\"margin-top:1em\"><strong>Hos anotherslegacy.dk får du:</strong><br>✓ Gratis fragt på alle produkter<br>✓ Pakken sendes inden for 1-2 dage<br>✓ Din pakke er forsikret under transport<br>✓ 14 dages guld bytte- og returret</p><p style=\"margin-top:1em\"><strong>Hos anotherslegacy har vi høje standarder, til de produkter vi sælger:</strong><br>• Alle produkter er blevet ultralydsrenset<br>• Alle produkter er gennemgået for fejl og mangler<br>• Alle produkter har fået en lødighedstest i røntgen maskine. Vi sælger IKKE forgyldte genstande</p><p style=\"margin-top:1em\"><strong>Mulighed for rentefri afdragsordning med Anyday:</strong><br>• Afdrag over 4 måneder<br>• Ingen skjulte gebyrer eller renter<br>Vælg Anyday under ”Betaling” når du køber smykket - Det tager 2 minutter at blive godkendt</p><p style=\"margin-top:1em\"><strong>Betal kontant:</strong><br>Vi tager imod op til 19.999 kroner kontant. Book en fremvisning i dag.</p><p style=\"margin-top:1em\"><strong>Butik:</strong><br>Store Kongensgade 68 kl th, 1264 København K<br>Mandag-Torsdag: 09:00-18.00<br>Fredag 09:00-17:00</p>",
handle: "GG4876",
id: 7608380522724,
product_type: "Ring",
published: true,
status: "active",
tags: "Ring, Anden type, Hvidguld, Kvinde, 14 karat, Diamantsmykke",
title: "Ring i 14 karat str. 61",
variants: [
{
sku: "GG4876",
price: 1999,
title: "Default Title",
weight: 4.25,
barcode: "",
taxable: true,
position: 1,
compare_at_price: null,
inventory_policy: "deny",
requires_shipping: true,
fulfillment_service: "manual",
inventory_management: "shopify",
inventory_quantity: 1,
},
],
vendor: "Andet",
webshop: "anotherslegacy",
cost_per_item: 914,
location: 67738140900,
},
}
Does anyone know how to solve this?
Solved! Go to the solution
This is an accepted solution.
I just noticed that for whatever reason, I don't have the variants ID. I will try to include that and get back.
This is an accepted solution.
I just noticed that for whatever reason, I don't have the variants ID. I will try to include that and get back.
That solved it...