I’ve implemented a basic scripting block in Airtable that attempts to send an update through an endpoint of my application. However, I’m encountering the following error when executing it, and I’m unsure about its meaning:
SyntaxError: Unexpected token C in JSON at position 0
Could someone help clarify what might be causing this issue? Here’s my code:
let token = await input.textAsync("Insert Token")
let table = base.getTable("test");
let record = await input.recordAsync('Pick a record', table)
let initialRaw = record.getCellValue("updatedcontent")
let recordid = "60cf7b6133fed78cdae3ca48"
let env = await input.buttonsAsync('Choose Environment',
['Test',
'Live'])
var exampleRequest = {
"items":[
{"ID":"1234",
"name":"Mr Smith"}
]
};
var exampleRaw = JSON.stringify(exampleRequest)
let raw = JSON.stringify(initialRaw)
let url = ''
if (env == 'live') {
url = 'https://live.com/user/' + recordid
} else {
url = 'https://test.com/user/' + recordid
}
console.log(url)
console.log(initialRaw)
console.log(raw)
console.log(exampleRequest)
console.log(exampleRaw)
//POST API LOCATION call
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer " + token);
myHeaders.append("Content-Type", "application/json")
myHeaders.append("Accept", "application/json")
var requestPostOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow',
body: exampleRaw
};
console.log(requestPostOptions)
let orderResponse = await fetch(url, requestPostOptions);
let finalResponse = await orderResponse.json()
console.log(finalResponse)
It seems to occur when trying to parse the response. Any insights on potential issues with my JSON management?