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.

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

POST /cart/add.js returns error 500

Solved

POST /cart/add.js returns error 500

plus13
Shopify Partner
7 1 1

Hello there,
I got 500 internal server error when using post cart add.js.
I wrote like that page, Example API calls.
https://shopify.dev/api/ajax/reference/cart

Could you tell me how to fix?

my code is

fetch(window.Shopify.routes.root + 'cart/add.js', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(toSend)
    })
    .then(response => {
      console.log(response.status);
      response.json;
    })
    .then(data => {
      console.log(data);
    })
    .catch((error) => {
      console.log('error:', error);
    });



Accepted Solution (1)

plus13
Shopify Partner
7 1 1

This is an accepted solution.

Sorry, I found the mistake...

that was 'toSend'. toSend has to be the array. 

View solution in original post

Reply 1 (1)

plus13
Shopify Partner
7 1 1

This is an accepted solution.

Sorry, I found the mistake...

that was 'toSend'. toSend has to be the array.