Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hello. I want to make a mutation, but I keep getting "invalid id" error. What am I doing wrong?
https://shopify.dev/api/storefront/2022-01/mutations/checkoutLineItemsUpdate
{%- for item in checkout.line_items -%}
{%- if forloop.first -%}
{%- assign line_item_id = item.id -%}
{%- assign variant_id = item.variant_id -%}
{%- assign line_item_qty = item.quantity -%}
{%- endif -%}
{%- endfor -%}
fetch('/api/2022-01/graphql.json', {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Storefront-Access-Token": "Token"
},
body: JSON.stringify({
query: "mutation checkoutLineItemsUpdate($checkoutId: ID!, $lineItems: [CheckoutLineItemUpdateInput!]!) {checkoutLineItemsUpdate(checkoutId: $checkoutId, lineItems: $lineItems) { checkout { id } checkoutUserErrors { code }}}",
variables: {
"checkoutId": "gid://shopify/Checkout/{{- checkout.id -}}",
"lineItems": {
"customAttributes": {
"key": "MyKey",
"value": "MyValue"
},
"id": "gid://shopify/LineItem/{{- line_item_id -}}",
"quantity": {{- line_item_qty -}},
"variantId": "gid://shopify/ProductVariant/{{- variant_id -}}"
}
}
}),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
};