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: "
**Guld Ring i 14 karat**
Vægt: 4.25 gram
Stand: Som ses på billeder, god stand med almindelige brugsspor og slidtage
**Hos anotherslegacy.dk får du:**
✓ Gratis fragt på alle produkter
✓ Pakken sendes inden for 1-2 dage
✓ Din pakke er forsikret under transport
✓ 14 dages guld bytte- og returret
**Hos anotherslegacy har vi høje standarder, til de produkter vi sælger:**
• Alle produkter er blevet ultralydsrenset
• Alle produkter er gennemgået for fejl og mangler
• Alle produkter har fået en lødighedstest i røntgen maskine. Vi sælger IKKE forgyldte genstande
**Mulighed for rentefri afdragsordning med Anyday:**
• Afdrag over 4 måneder
• Ingen skjulte gebyrer eller renter
Vælg Anyday under ”Betaling” når du køber smykket - Det tager 2 minutter at blive godkendt
**Betal kontant:**
Vi tager imod op til 19.999 kroner kontant. Book en fremvisning i dag.
**Butik:**
Store Kongensgade 68 kl th, 1264 København K
Mandag-Torsdag: 09:00-18.00
Fredag 09:00-17:00
",
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?