Storefront API checkoutCreate Variant is invalid

Abdelhakim_Lahr
Visitor
2 0 1

I'm trying to create a new checkout using the new storefront API, I'm using the checkoutCreate mutation, and I'm passing in the lineItems argument the correct variant id where I'm getting from here (see the image bellow), and I get alwaise an error with the message Variant is invalid

 

Replies 8 (8)

mak1
Shopify Partner
3 0 0

@abdelhakim were you able to resolve it ?

Abdelhakim_Lahr
Visitor
2 0 1

@mak no still have the same issue

Muthu_Somasund1
Shopify Partner
37 0 4

Which variantid you have used?.. You should not use variantid as like in shopify admin(in numbers such as 343345222). You should use variantid  returned by fetching variant using store front API ( such as Zedfrigrenjdfkjknkrgkrgkrngrg=)

mak1
Shopify Partner
3 0 0

Hi Muthu,

Following is the request I made where Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk2NzU4MzM0MTY= is the variant ID used which I got from Shopify's Admin as mentioned by @abdelhakim

mutation{  
      checkoutCreate(input:{  
         email:"mak@example.com",
         allowPartialAddresses:true,
         shippingAddress:{  
            city:"Toronto",
            province:"ON",
            country:"Canada"
         },
         lineItems:{  
            variantId:"Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk2NzU4MzM0MTY=",
            quantity:1
         }
      }) 
}

Muthu_Somasund1
Shopify Partner
37 0 4

Hi mak,

Have you published the product to the sales channel? this is required to access the product and its variants

mak1
Shopify Partner
3 0 0

Hi Muthu,

Yes, I've published the product to all the sales channel.

 

XuoriG
Shopify Staff (Retired)
1 0 0

Hello @abdelhakim & @mak!

I took a look at your problem and it seems like you are using a Product ID, and not a Product Variant ID!

When you are fetching products, make sure you get all variants for the products by querying them like this:

query {
  shop{
    products(first: 5) {
      edges {
        node {
          variants(first: 5) {
            edges {
              node {
                id
              }
            }
          }
        }
      }
    }
  }
}

 

Let me know if that fixes your problem!

To learn more visit the Shopify Help Center or the Community Blog.

Logan_Tighe
Tourist
5 0 1

@muthu "Have you published the product to the sales channel? this is required to access the product and its variants"

 

Thanks for the answer.