We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Product isn't adding in the cart through Cart Api

Solved

Product isn't adding in the cart through Cart Api

Divya
Shopify Partner
10 0 1

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.

Accepted Solution (1)
BSSCommerce-B2B
Shopify Partner
1972 564 567

This is an accepted solution.

I think you are missing the header "Content-Type": "application/json"

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

View solution in original post

Replies 3 (3)

BSSCommerce-B2B
Shopify Partner
1972 564 567

Hi @Divya,

I follow Shopify AJAX Cart API and it works. Can you show your code so I can take a look?

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

Divya
Shopify Partner
10 0 1

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}`, "frame": frameNames[i] } }]}


ERROR:

Request Method:
POST
Status Code:
400 Bad Request
Remote Address:
[2620:127:f00f:e::]:443
Referrer Policy:
strict-origin-when-cross-origin
BSSCommerce-B2B
Shopify Partner
1972 564 567

This is an accepted solution.

I think you are missing the header "Content-Type": "application/json"

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now