Getting 500 Internal Server Error using POST /cart/add.js

WebContrive
Shopify Expert
26 0 3

Hello There,

I'm getting 500 Internal Server Error when adding products using a Cart AJAX API(/cart/add.js).

Can anyone help me to fix this issue?

Below is the code which I'm using:

 

let $th_id_array = new Array(); 
$th_id_array.push({ id: 123, quantity: 1, }); 
const $th_bundle_formData = {items: $th_id_array}; 
fetch('/cart/add.js', { 
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify($th_bundle_formData) 
}).then(response => response.json()).then($th_addtocart_result => { 
  if($th_addtocart_result.items.length > 0){ 
    console.error($th_addtocart_result); 
  } 
}).catch(($th_addtocart_error) => {
  console.error($th_addtocart_error); 
});

 

banned
Replies 2 (2)

Matt-Pipelabs
Excursionist
13 1 1

Hey @WebContrive ,

If you open up the Developer Tools in your browser, open the Network tab and click into the request that is failing you should be able to see the reason why.

WebContrive
Shopify Expert
26 0 3

Hello @Matt-Pipelabs,

Thank you so much for your quick response.

I have checked the Network tab and it is also showing the same error (500 Internal Server Error).

banned