Need assistance with syntax error in Airtable script block

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?

This happens when your API returns HTML instead of JSON - usually from auth issues or server errors. The “C” at position 0 means the response starts with something like “Cannot” instead of valid JSON. Add error handling before calling .json() on your response. Check orderResponse.status and orderResponse.ok first, then use orderResponse.text() to see what you’re actually getting. In my experience, this usually means your Bearer token’s invalid, wrong endpoint URL, or the server’s returning an error page. Also double-check that your endpoint actually accepts POST requests - some APIs return HTML error pages for unsupported methods.