Cr4shBarcode
Cr4shBarcode3w ago

Is there a way to store API response as JSON/object instead of text/string?

I'm brand-new to coding, so forgive me if this is a dumb question or an obvious fix, I just can't see it. I'm doing an API call on an appointment scheduler to get a list of currently booked appointments for a user. I know for a fact that there are a total of two appointments on the schedule. The response body lists them as "0" and "1" respectively. I'm getting an error that ChatGPT says might be because API mapping stored the response as a stringified object via .toString(), instead of as proper JSON. How can I ensure that the captured response from the API call is being stored as JSON and not text? Note: If I change " response " to " resonse.* " in the capture section, the API will return only one, not both, appointments. If I change it back to " response " it throws the error.
No description
2 Replies
Tico | Voiceflow Assistant
Voiceflow’s API Step can read full JSON bodies, but the variables you capture into can only hold primitive values (string, number, boolean). What happens in your case • When you map response to a variable, Voiceflow tries to drop the whole object/array into that variable → it gets coerced to a string ("[object Object]"). Most schedulers then reject that value when you send it back, which is the error you’re seeing. • Mapping response.* tells Voiceflow to grab the first property it finds under response, so you only see the first appointment and the error disappears. How to work with the JSON correctly 1. Keep the raw payload – Capture it to a variable anyway (e.g. raw_appointments). It will be stored as a string. – In the very next Function step run:
const list = JSON.parse(raw_appointments); // now a real array
// …work with list[0], list[1] etc.

const list = JSON.parse(raw_appointments); // now a real array
// …work with list[0], list[1] etc.

– Anything you want to pass to later steps must be sent back via outputVars, using JSON.stringify again if it’s still an array/object. 2. Or capture just what you need – If the response looks like [ { …appt0… }, { …appt1… } ], you can map: • response.0appt_oneresponse.1appt_two (Use the “preview request” button, click the elements and Voiceflow will write the paths for you.) Key takeaway: Voiceflow variables themselves can’t hold objects; wrap/unwrap with JSON.parse / stringify inside a Function step, or capture individual properties instead. Docs for reference → https://docs.voiceflow.com (section: API Step › Capture Response)
Steve B. | IntelleSync.ai
Can you share screenshot of your api resposne?

Did you find this page helpful?