Shopify js sdk Variant is invalid

1 0 0

I Faced an issue with JS SDK


While Trying to do 

const lineItemsToAdd = [
                          variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==',
                          quantity: 1
const shippingAddress = {
                      address1: self.selectedAddress.address1,
                      address2: self.selectedAddress.address2,
                      company: null,
                      firstName: 'Bob',
                      lastName: 'Norman',
                      zip: '11001'

await client.checkout.updateShippingAddress(, shippingAddress);

 let mainCheckoutId = await client.checkout.addLineItems(, lineItemsToAdd);

 address works find but the 

mainCheckoutId.lineItems = null
userErrors retuns message ="Variant is invalid";


i tried many products and all are published to online sale channel  


any suggestions please ???

Replies 2 (2)

1 0 0

I had this same issue.

It happened, when I altered the variants of a product in the Shopify admin.  I also had a checkout that maintained a reference to the now defunct variants.

The solution is to discard the checkout that has reference to the old variant ids. As I maintained a reference to the checkout id in LocalStorage it was a simple matter of clearing the checkoutId from LocalStorage to fix this problem



7 0 1

I just spent many hours on this issue myself and I'm convinced that the docs are vague to force you to ask for help, at which point they say it's complicated and refer you to the certified "experts".  

Maybe this will point you and others in the right direction.  Look at the variant object for the the property "admin_graphql_api_id" that is a string starting with "gid://shopify....." and base64encode that using the JS function btoa( passing in the string ) and try adding the result to the checkout as the "variantId"

Not happy about the intentional ambiguity at all