I’m currently trying to upload data from Airtable to Voiceflow.
So far, I’ve successfully made a GET request to Airtable and stored the data in a variable in Postman. However, when I make my POST request, I receive the following error:
To my knowledge you cannot execute JSON.parse in a variable replacement on the body. You can however leverage the pre-request script to set that as a variable then send the variable in the POST
Thanks for coming to me the issue was that my post request was not in the format voiceflow expected, so with the help of ChatGPT I created the below pre-request script (which is the solution)
// ‘voiceflow_data (Is is the variable you must created to store your data from the GET request)’
let voiceflow_data_parsed = JSON.parse(pm.environment.get(“voiceflow_data”)); // Parse the data
let formattedData = {
“data”: {
“name”: “Pick your document title”,
“schema”: {
“searchableFields”: [“xxx”, “xxx”, “xxx”, “xxx”],
“metadataFields”: [“YYY”, “YYY”]
},
“items”: voiceflow_data_parsed.fields // This assumes ‘fields’ is an array of objects from your GET request
}
};
// Convert to string before sending
let finalPayload = JSON.stringify(formattedData);
// Store the formatted payload to send in the POST request
pm.environment.set(“voiceflow_payload”, finalPayload);
Also apologies if the code is inaccurate. I am new to development and I am only dipping my toe in as I am focusing on AI automation.