Ajax post call is not working with token too gives 404 error

Terry201
Visitor
1 0 0

Hi 

I am working on some custom code and found when i am making ajax post call it gives 404 error

Need to call this section and get data is my primary concern.

simple ajax with post call gives 404 error though website page/section is working perfectly.

Error: https://prnt.sc/59wqwAGtBopm
Working url: https://theearthbands.com/?sections=johntest


 

Below is demo code which is not working it is as simple as to work so that i can apply my logic to others

 

 

 

const endpointUrl = '/?sections=johntest';
const apiKey = 'key added'; // Replace with your actual API key
$('#calculatorForm').on('click', function() {
const dataToSend = {
  key1: 'value1',
  key2: 'value2'
};
fetch(endpointUrl, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}` // Include the authorization header
  },
  body: JSON.stringify(dataToSend)
})
  .then(response => response.json())
  .then(responseData => {
    console.log('Response:', responseData);
  })
  .catch(error => {
    console.error('Error:', error);
  });
});

 

 

 

 

 


Help is much appreciated 

Reply 1 (1)

tim
Shopify Expert
3483 282 1290

Section rendering API does not require authorization and you can't pass any data, so there is no need to POST.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com