Development discussions around Shopify APIs
Hey there,
const lineItemsToAdd = [ { // Here they are using the variantID and not just product ID variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==', quantity: 5, customAttributes: [{key: "MyKey", value: "MyValue"}] } ];
const lineItemsToUpdate = [ { // Here they are using regular product ID and not variantID id: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=', quantity: 2 } ];
const lineItemIdsToRemove = [ // And here I guess its the regular product ID because its the same as above 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' ];
[{ "message":"invalid id", "locations":[{"line":1,"column":2186}], "path":["checkoutLineItemsRemove"] }]
TypeError: Cannot read property 'checkoutLineItemsAdd' of undefined
Think of line items as a resource of their own, like an instance of a variant (but not a variant). You need to provide a variant when creating a line item object so we know what variant that line item is an instance of. From there, the line item has an ID of its own, and can be referred to with that ID for when you are removing or updating line items. The only time you should need the variant ID is when creating (adding) a line item.
Inventory is stored in inventory levels. You could make a GraphQL query like this to get total, and location-specific inventory counts:
{ productVariants(first:10){ edges { node { inventoryQuantity inventoryItem { inventoryLevels(first:10){ edges { node { id available location { name } } } } } } } } }
Hope that helps a bit.
Cheers.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hey there Alex,
Thanks a lot, thats the information I have been missing. Nobody was able to tell me this until now, not even Shopify staff before you.
Cheers,
Jousi
Hi,
I came across this question while also adding line items to my checkout.
Does this mean that the new id returned when calling
client.checkout.addLineItems
needs to be stored and matched against the variantId?
Otherwise, I can't figure out how to
client.checkout.updateLineItems
properly as I am also getting an error when trying to call updateLineItems with the id or variantId of the product.
It seems to work when I call updateLineItems with the id returned after calling addLineItems.
Thank you for any help.
User | RANK |
---|---|
10 | |
4 | |
3 | |
3 | |
3 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023