Quotation marks api call fail
Hey guys. Can someone help me how to setup my agent just before the Api call step I need to make sure that my API call doesnt fail when user writes quotation marks. Thanks
3 Replies
Here are the two easiest ways to protect your API call from breaking when the user’s message contains quotation marks ( " or ' ).
1️⃣ Let Voiceflow do the escaping for you (JSON body)
• In the API step set the Body type to JSON.
• Add your variable as a value, without wrapping it in quotes: When the request is sent Voiceflow serialises the body with
2️⃣ Pre-process the text yourself (works for query-strings, headers, or raw bodies) Add a Function step just before the API step and create an “escaped” version of the text: If the text is going into a URL query parameter you can instead encode it: 3️⃣ Use the new value in the API step Replace every occurrence of
With either approach the request that reaches your backend will always be valid, even when the user types:
• Add your variable as a value, without wrapping it in quotes: When the request is sent Voiceflow serialises the body with
JSON.stringify()
, so any quotes inside user_input
are automatically escaped (e.g. He said "hi"
).2️⃣ Pre-process the text yourself (works for query-strings, headers, or raw bodies) Add a Function step just before the API step and create an “escaped” version of the text: If the text is going into a URL query parameter you can instead encode it: 3️⃣ Use the new value in the API step Replace every occurrence of
{{user_input}}
with {{safe_text}}
(or whatever name you chose).With either approach the request that reaches your backend will always be valid, even when the user types:
She answered: "I’m in!" 😄Docs: https://docs.voiceflow.com
I would appreciate getting more help not just from AI thanks
you just need to JSON.stringify() the var.