I’ve used the cart Api in a tool and embedded it within the extension app block, and passed the variant id and quantity to it but it gives 400 Bad request error and the product doesnt add to cart.
Hi @Divya_3 ,
I follow Shopify AJAX Cart API and it works. Can you show your code so I can take a look?
Hello @BSSCommerce-B2B ,
Here’s the code
const res = await fetch(https://${completeData?.shop}/cart/add.js, {
method: ‘POST’,
body: JSON.stringify(data)
})
Response:
{items:[{ “id”:49019420148010 /allStyle[i].variantId/, “quantity”: 1, “properties”: { “_download”: [https://photo-frame.fly.dev/api/orderPrint/${data](https://photo-frame.fly.dev/api/orderPrint/${data)}, “frame”: frameNames[i] } }]}
ERROR:
Request URL:
https://designtool678.myshopify.com/cart/add.js
Request Method:
POST
Status Code:
400 Bad Request
Remote Address:
[2620:127:f00f:e::]:443
Referrer Policy:
strict-origin-when-cross-origin
I think you are missing the header “Content-Type”: “application/json”