Unable to format JSON data to call 3rd party webservice

I have problem formatting my JSON data after referring to some samples for reference and I have syntax errors in my codes and I could not resolve the syntax errors. The syntax errors are pointing to my newdata.

Please see my codes below and advise how I should change my codes.

For your info, I used Postman with the following request data and I was able to get a successful response.

Request data:

Response data:

Please post copyable code and not a screenshot.

Anyway, I don’t see a problem with your code (assuming you used real URL and not the word “url”).

Sorry, I am having issues posting the codes here as I got error prompting that I have links in my posting but I have removed them but it is still not allowed.

I have to screenshot the error message from my Wix editor for the newdata and body variable.

Please take a look and advise what could have gone wrong.

Thanks.

I may have found the root cause of the failure when I tried to call the webservice but have no idea how to resolve it.

The issue lies with the header content type.

headers : {
“content-type” : “application/json”
},

When it is received at the 3rd party server, the header content type became text/plain instead of application/json.

How can I set the header content type which I already set in my code as shown above.

Please advise.

Thanks.

I think this is an editor alert and not something that will break your code.
If instead of

newData = JSON.stringify(newData);

You’ll use:

const newDataJson = JSON.stringify(newData);
//..
body: newDataJson,
//....

You won’t see it.

Have you thought about working with a third party library such as Axios? That way you don’t even have to call JSON.stringify on the request body. Difference between Fetch and Axios.js for making http requests - GeeksforGeeks

@jonatandor35 Thanks. I have added the new constant as suggested and the alert is gone.

I have managed to move the calling of the fetch API to backend code and the “content-type” in the header was successfully changed to “application/json” and the call was successful with the response that I was expecting.

Thanks so much for the guidance especially from J.D.