Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

GraphQL checkoutLineItemsUpdate

GraphQL checkoutLineItemsUpdate

oleksandr_OD
Visitor
1 0 0

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);
            });
    };

 Screenshot_1.pngScreenshot_2.png

Overdose Digital
Replies 0 (0)