Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

How can I use the car add API adding a variant by id and sku?

How can I use the car add API adding a variant by id and sku?

jacobfung
Visitor
3 0 0

when i trying to fetch the cart api on page code, like this, 

jacobfung_0-1665373754267.png

but clearly there is not a right way,

jacobfung_1-1665373786830.png

 

What is the best way to finish it?

what else params should I add on this?

Replies 3 (3)

Jason
Shopify Partner
11206 226 2315

The cart AJAX api would be wanting a variant ID - not a product ID. The error makes sense since it looks like you're sending over a product ID.

That's noted in the docs:


In the following example, quantity is the amount of the variant that you want to add and id is the variant ID of that variant. You can add multiple variants to the cart by appending more objects in the items array.
https://shopify.dev/api/ajax/reference/cart#post-locale-cart-add-js

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
jacobfung
Visitor
3 0 0

Got you,

but how can I get the variant ID from my product detail page?

jacobfung
Visitor
3 0 0

how can I get the variant ID from my product detail page?