js-buy-sdk: Cannot update or delete line items

Bug: Cannot update or delete line items.

{
variantId: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xMzEzMDM4NzQyMzI4Nw==", quantity: 1
}

is added successfully.

However, trying to update or delete the line item, the console prints: Uncaught (in promise) Error: [{"field":null,"message":"Line item with id 2815e3d64efc21a40e226cab0cd308f5 not found","code":"LINE_ITEM_NOT_FOUND"}]

Request headers:

Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Encoding: gzip
Content-Language: en
Content-Security-Policy: frame-ancestors 'none'; report-uri /csp-report?source%5Baction%5D=query&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=api%2Fgraphql&source%5Bsection%5D=api&source%5Buuid%5D=80e9ed30-c2fb-4f47-a54d-bdd542f42f6c
Content-Type: application/json; charset=utf-8
Date: Fri, 15 Mar 2019 17:04:42 GMT
Server: nginx
Strict-Transport-Security: max-age=7889238
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff, nosniff
X-Dc: chi2,gcp-us-east1
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 80e9ed30-c2fb-4f47-a54d-bdd542f42f6c
X-ShardId: 54
X-ShopId: 1091207223
X-Shopify-API-Deprecated-Reason: https://help.shopify.com/api/getting-started/api-deprecations
X-Shopify-Stage: production
X-Sorting-Hat-PodId: 54
X-Sorting-Hat-ShopId: 1091207223

Response: {"data":{"checkoutLineItemsUpdate":{"userErrors":[{"field":null,"message":"Line item with id 84aad89cedfa0ba08b1bf6538c1a8828 not found"}],"checkoutUserErrors":[{"field":null,"message":"Line item with id 84aad89cedfa0ba08b1bf6538c1a8828 not found","code":"LINE_ITEM_NOT_FOUND"}],"checkout":null}}}

Environment: MacOS Mojave 10.14.3 Chrome 73.0.3683.75 Safari 12.0.3

iOS 12.2 Mobile Safari

SDK Version 2.1.1

My thoughts: The part I really am confused by is this has been working fine since the merchant launched two weeks ago. It just started happening out of the blue a couple of days ago with no changes to our implementation whatsoever.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

So, I figured how this works. Updatelineitems require both line id and variant id. See below:

`var checkoutIdF = ‘Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xYTJhZjkwMjNlNjVlN2YxNWM1MWIyMmNkZTkzNzU1Yj9rZXk9NTUzNGEzOTMyMDY4Yzc5ZWRlMGQ5NzkyMmI5MzFmOGM=’;

var lineItemsF = [ { id: “Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtLzQxMTI3MjQ3MTE4NTE2MD9jaGVja291dD0xYTJhZjkwMjNlNjVlN2YxNWM1MWIyMmNkZTkzNzU1Yg==”,

quantity: 0,

variantId: “Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MTEyNzI0NzExODUxNg==”

} ];

client.checkout.updateLineItems(checkoutIdF, lineItemsF).then((checkout) => {

console.log(checkout);

});`

I hope someone from Shopify updates this to their docs page.

@rebeccajfriedman @jmignac Is this issue actually resolved? If so, can you point me to the PR? If not, I’m curious why this issue is closed. I seem to be experiencing this issue using the latest Javascript client (shopify-buy 2.10.0).

If this is still an issue, is there a work around for shopify-buy 2.10.0?

Steps to Reproduce

It’s difficult to provide a complete set of steps to reproduce because I have to add multiple items to get my cart in a state that yields the error, but if it helps, these HTTP headers were included in the response that yielded an error:

cf-request-id: 038f3722bd0000bb528013c200000001
x-request-id: 4e65734c-b650-426a-9a43-56ee52ae5b82

After adding multiple items, the checkout has 5 line items. Here is a subset of the JSON for the checkout:

Screen Shot 2020-06-25 at 3 35 17 PM

But when I call client.checkout.removeLineItems(checkout.id, [lineItem.id]) for the line item at index 2, I get the following error:

Error: [{"field":null,"message":"Line item with id 339915036754511 not found","code":"LINE_ITEM_NOT_FOUND"}]

Also, if I remove the line item at index 3, then the line items at index 2 and 3 are both removed. Very strange.

We’ve also added a checkout.replaceLineItems method that you can use: https://github.com/Shopify/js-buy-sdk/blob/master/src/checkout-resource.js#L205-L224

I’m not sure what’s going wrong, as I just executed your query locally on my test shop and I got a valid response.

const checkoutMutation = `mutation checkoutLineItemsReplace($checkoutId: ID!, $lineItems: [CheckoutLineItemInput!]!) {
      checkoutLineItemsReplace(checkoutId: $checkoutId, lineItems: $lineItems) {
        checkout {
          id
        }
        userErrors {
          code
          field
          message
        }
      }
    }`

const checkoutId = "Z2lkOi8vc2hvcGlmeS9DaGVja291dC83YTBkYTAzYWZjMWM4MTBhYzI1YjgxNjQyMzdkMzM3Nz9rZXk9YTlkZTM1ZmQzODYwZTFkZDdjZGQwYzA3NTBlMWFhNjY=";
const lineItems = [{"variantId": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xMzg3MDQ4MzQ3MjQwNg==", "quantity": 5}];

fetch('https://MYSHOPIFY_DOMAIN/api/graphql', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Shopify-Storefront-Access-Token': storefrontAccessToken
      },
      body: JSON.stringify({ query: checkoutMutation, variables: {checkoutId: checkoutId, lineItems: lineItems} })
    })
    .then(res => res.json())
    .then(res => {
      console.log(res);
    });

Some things that could be going wrong:

  • Your variantId or checkoutId might be invalid (they should look similar to mine above)
  • You are attempting to mutate a checkout that was not created using the same access token that you are using in this mutation

When you get an error response back, it should have a “request ID” in the message. If you provide the request ID, we can look at your case specifically.

Did anybody find a solution to this issue?

Necroing the bug as it still isn’t fixed in 2.5 years. What more, it is still documented and suggested in documentation to use checkoutLineItemsUpdate instead of replace.