Seeking clarification on a syntax issue in an Airtable scripting block

Recently, I integrated a basic Airtable script block that sends an update to an API endpoint in my application. However, when I run the script, I receive an error: “SyntaxError: Unexpected token C in JSON at position 0.” I suspect a small mistake might be causing this problem and would appreciate any insights or experiences in resolving such an error.

let authKey = await input.textAsync("Enter your authentication key");
let recordCollection = base.getTable("sampleTable");
let chosenRecord = await input.recordAsync("Select a record", recordCollection);
let contentValue = chosenRecord.getCellValue("contentField");
let uniqueId = "ABC123XYZ";

let chosenEnv = await input.buttonsAsync("Select Environment", ["Development", "Production"]);

let apiData = {
    dataList: [
        {
            code: "5678",
            fullName: "Jane Doe"
        }
    ]
};

let jsonData = JSON.stringify(apiData);
let apiEndpoint = '';

if (chosenEnv === "Production") {
    apiEndpoint = 'https://api.productionservice.com/item/' + uniqueId;
} else {
    apiEndpoint = 'https://api.devservice.com/item/' + uniqueId;
}

console.log(apiEndpoint);
console.log(contentValue);
console.log(jsonData);

let headersSet = new Headers();
headersSet.append("Authorization", "Bearer " + authKey);
headersSet.append("Content-Type", "application/json");

let postParams = {
    method: 'POST',
    headers: headersSet,
    body: jsonData
};

console.log(postParams);

let response = await fetch(apiEndpoint, postParams);
let jsonResponse = await response.json();
console.log(jsonResponse);

Based on my experience, the error usually occurs when the server does not return the expected JSON output. I encountered a similar problem when the endpoint was configured inconsistently with the development environment, leading it to send back HTML instead. I recommend checking the server response using response.text() to inspect the raw data and confirm it is indeed JSON. Additionally, validating your API key and endpoint configuration could help, as misconfigurations often result in unexpected output that hinders JSON parsing.

hey, seems like your endpoint might be sending back non-json (maybe html). try using response.text() to debug, then fix the actual content. also check that your content field isn’t causing extra output, might b a mismatch