
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Nov 29, 2023 06:19 PM
Hello there,
I'm trying to fetch data from a product in one base, then send that information to an external API and then update that new info in other base. The code goes like this:
//input of modified product
let inputConfig = input.config();
//JSON creation
let body = {
"costo_ult": inputConfig.costo_ult[0],
"disponible": inputConfig.disp[0],
"dias_obs": inputConfig.dias_obs[0]
}
console.log(body);
console.log(JSON.stringify(body));
//Send JSON to API
try {
let response = await fetch(`http://167..../${inputConfig.id[0]}`, {
method: 'PATCH',
body: JSON.stringify(body),
headers: {
'Origin': '',
'Content-Type': 'application/json ; charset=utf-8',
'Authorization': 'eyJhb...',
},
});
console.log(await response.json());
}
catch (error) {
console.log(error);
}
The fields I want to update are related to costs, quantities and rotation days, and the response from the script is
- Error {name: "SyntaxError"}
- name: "SyntaxError"
So, can anyone explain me why this is happening and how to solve it? Thanks!
Solved! Go to Solution.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Dec 01, 2023 06:05 AM
Hi Richard - Have you tried hard-coding values (instead of referencing `inputConfig`) to see if that helps troubleshoot?
When I did that, and tested with an endpoint from https://webhook.site/ that returned proper JSON, I did not get an error. You can also try changing your `await response.json()` to `await response.text()` to see if perhaps the issue is coming up since your endpoint is not returning JSON as you expected.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Dec 01, 2023 06:05 AM
Hi Richard - Have you tried hard-coding values (instead of referencing `inputConfig`) to see if that helps troubleshoot?
When I did that, and tested with an endpoint from https://webhook.site/ that returned proper JSON, I did not get an error. You can also try changing your `await response.json()` to `await response.text()` to see if perhaps the issue is coming up since your endpoint is not returning JSON as you expected.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Dec 02, 2023 08:26 PM
Hello there @marks and thanks for the reply!
As you suggested, I tried hard-coding values and I discovered that the resource was missing while fetching the API's link. Everything's working fine now!
