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 how to access product variantID? JS Buy SDK requires it for adding to checkout.

Graphql how to access product variantID? JS Buy SDK requires it for adding to checkout.

h0rhay
Visitor
2 0 0

Hi,

I'm trying to set up a checkout with the JS Buy SDK.

I'm using a Gatsby front end, using the gatsby-source-shopify 5.1.0 plugin.

In the example below from shopify docs, you can see the checkout requires a `variantId` to reference the product.

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout
const lineItemsToAdd = [
  {
    variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==',
    quantity: 5,
    customAttributes: [{key: "MyKey", value: "MyValue"}]
  }
];

// Add an item to the checkout
client.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout.lineItems); // Array with one additional line item
});

 

In my graphql data layer I can only see `shopifyId` there is no reference to a `variantId`..

How can I access the variantId?   

(the shopifyId is the wrong format: `gid://shopify/ProductVariant/40890427080873`)

Many thanks 🙏

Reply 1 (1)

AROO
Visitor
1 0 0

I have the same issue!