client.checkout.updateLineItems - is expecting a global id ?

xmanalex
New Member
5 0 0

I'm trying to use updateLineItems of checkout according to the specification would pass the checkoutID according the migration guide here:

https://github.com/Shopify/js-buy-sdk/blob/master/tutorials/MIGRATION_GUIDE.md

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID from a previous checkout.create call

const lineItemId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ='; const lineItems = [ {id: lineItemId, quantity: 1} ];

client.checkout.updateLineItems(checkoutId, lineItems).then((checkout) => {
console.log(checkout);
// Checkout with a line item quantity updated to 1 console.log(checkout.lineItems) // Line items on the checkout
});
client.checkout.updateLineItems

 however when I pass the checkoutID,  it appears to me the api is expecting a globalid.  

(index):200 Error: [{"message":"Variable $checkoutId of type ID! was provided invalid value","locations":[{"line":1,"column":3229}],"extensions":{"value":"Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNWEzZjM5MmRjNWY0NjBiNDI1Y2Q5YTI0MzliMDcyMj9rZXk9NmUzYmUwZmE4YTM4YTEyNTRkMTNhN2I1N2I0YmI0MDA","problems":[{"path":[],"explanation":"Invalid global id `Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNWEzZjM5MmRjNWY0NjBiNDI1Y2Q5YTI0MzliMDcyMj9rZXk9NmUzYmUwZmE4YTM4YTEyNTRkMTNhN2I1N2I0YmI0MDA`","message":"Invalid global id `Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNWEzZjM5MmRjNWY0NjBiNDI1Y2Q5YTI0MzliMDcyMj9rZXk9NmUzYmUwZmE4YTM4YTEyNTRkMTNhN2I1N2I0YmI0MDA`"}]}}]

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 238

I've never used this package, but shouldn't your property be variantId not just id?

From the migration docs example...

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID from a previous checkout.create call
const lineItems = [
  {variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yNTYwMjIzNTk3Ng==', quantity: 5},
  // Line items can also have additional custom attributes
  {
    variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yNTYwMjIzNjA0MA==',
    quantity: 2, 
    customAttributes: {'key': 'attributeKey', 'value': 'attributeValue'}
  }
];

client.checkout.addLineItems(checkoutId, lineItems).then((checkout) => {
  console.log(checkout); // Checkout with two additional line items
  console.log(checkout.lineItems) // Line items on the checkout
});
0 Likes
xmanalex
New Member
5 0 0

Thanks but the issue is with the checkout id 

(although I am passing the variant id  which yes you would be correct)

const lineItems = [
id: cartLineItem.variant.id, quantity: 1}
];

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 238

You might be passing in the variable's value correctly, but the property name looked wrong. It needs to be like this...

 

const lineItems = [
  {variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yNTYwMjIzNTk3Ng==', quantity: 5}
];

 

0 Likes
xmanalex
New Member
5 0 0

ah yes thank you that is observant,  i see what you mean that property of the variantId vs the id:

I did just try that above, and am getting the same error back regarding the type of id passed for the checkout id:

 

The error message is pretty specific :

Variable $checkoutId of type ID! was provided invalid value

value:"Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNWEzZjM5MmRjNWY0NjBiNDI1Y2Q5YTI0MzliMDcyMj9rZXk9NmUzYmUwZmE4YTM4YTEyNTRkMTNhN2I1N2I0YmI0MDA","

problems: Invalid global id `Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNWEzZjM5MmRjNWY0NjBiNDI1Y2Q5YTI0MzliMDcyMj9rZXk9NmUzYmUwZmE4YTM4YTEyNTRkMTNhN2I1N2I0YmI0MDA`","

message":"Invalid global id

 

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 238

And you've verified that the checkoutId is indeed correct and the object is in the proper state to be queried? And I apologize, as the example I provided was for adding a new line item to the cart. Your exercise was updating an existing cart line item. So your use of id: and not variantId: was correct all along. As long as the checkoutId is valid, and the lineItemId is an existing line item for that checkout then it should work!

0 Likes
xmanalex
New Member
5 0 0

It is the same checkout id I am using in the rest of the script to  add items to the cart for sure.

 

client.checkout.create().then((checkout) => {
checkoutId = checkout.id;
});

   and i use that elsewhere in the app and it fine. 

client.checkout.fetch(checkoutId).then((checkout) => {
const cartLineItems = checkout.lineItems.map(function (lineItem, index) {
});

let button = document.createElement("button");
button.innerHTML = "Get me some {{ product.title }} !";
button.setAttribute('id', checkout.webUrl);
document.getElementById("checkout").appendChild(button);
});

 

The only spot where have had an issue is the update of the line items as from the docs on the js-buy github repo

Screen Shot 2020-12-21 at 1.31.46 PM.png

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 238

If you are running through the basic examples they are providing and it's not working as expected, I'd suggest raising an issue on the project's GitHub page. It should be pretty cut and dried as long as the the ID's are correct. Must be something quirky in the project's source. Sorry!

0 Likes
xmanalex
New Member
5 0 0

no worries thanks much for your  discussion

0 Likes
omakse33
New Member
2 0 0

It's a piece embarrassing, however I wanted to publish my mistake here in case it enables anybody else whilst beginning to apply the node patron.

0 Likes