aa
aa8h ago

hey team - hoping someone can help but they'd need to be experienced. Around an API call and parsing

Im making an api call and the api responds with the value i need using postman. But it is the body straight as a string. Then VF is parsing it to make an object which i cant think access. Tried everything, looping through it, capturing different parts of the response. Nothing...
1 Reply
Tico | Voiceflow Assistant
Here’s what’s happening and the quick ways to fix it: Why the response looks wrong in the API step • The API step automatically tries to read the body as JSON.
• If the server actually sends back plain text (or sends text but labels it application/json) Voiceflow still tries to parse it → you end up with an odd-looking “object” that you can’t drill into. 3 ways to solve it 1️⃣ Ask the API for real JSON (best) • Add Accept: application/json on your request and make sure the endpoint really returns { "value": "…" }.
• Then you can capture it with response.value in the Capture Response section. 2️⃣ Capture the whole raw body from the API step • In the Capture Response table just type response (no dot path) in the Path column and map it to a variable (e.g. raw_response).
• You’ll get the entire string exactly as Postman shows it.
• If it’s JSON-looking text you can JSON.parse it later in a Code/Function step. 3️⃣ Switch to a Function step and tell fetch to parse as text
export default async function main(args) {
const res = await fetch(args.inputVars.url, // or hard-code the URL
{ method: 'GET' }, // your method / headers
{ parseType: 'text' } // 👈 force plain-text parsing
);

const body = res.text; // raw string
// do any splitting / JSON.parse(body) etc.
return {
outputVars: { raw_response: body }
};
}
export default async function main(args) {
const res = await fetch(args.inputVars.url, // or hard-code the URL
{ method: 'GET' }, // your method / headers
{ parseType: 'text' } // 👈 force plain-text parsing
);

const body = res.text; // raw string
// do any splitting / JSON.parse(body) etc.
return {
outputVars: { raw_response: body }
};
}
parseType: 'text' stops Voiceflow from trying to JSON-parse the response for you. Choose whichever option fits your situation – usually #2 is the fastest if you can’t change the external API, and #3 gives you full control if you need to post-process the string inside Voiceflow. More details: https://docs.voiceflow.com

Did you find this page helpful?