plain-purple
plain-purple2y ago

For the pro Javascript users - help?

Hoping to get help on this this is an array and I am struggling to put this into the body of a Post API call. Any advice on how I could do this? patient_phone_numbers: [ { phone_type: 'Mobile', number: '0-123-456-78' } ] }) I've tried doing this directly under 'Raw' but it's not working cuz obviously, I don't know what I am missing lol. I'm getting 400 bad request
No description
9 Replies
Tico | Voiceflow Assistant
Based on your expertise level and the context provided, it seems like you're trying to make a POST request using the Voiceflow Fetch API in JavaScript. Here's how you can do it:
await fetch('<YOUR-URL-HERE>', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
patient_phone_numbers: [
{
phone_type: 'Mobile',
number: '0-123-456-78'
}
]
})
});
await fetch('<YOUR-URL-HERE>', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
patient_phone_numbers: [
{
phone_type: 'Mobile',
number: '0-123-456-78'
}
]
})
});
In this example, the fetch function is used to make a POST request to the specified URL. The method property in the options object is set to 'POST', indicating the type of request. The headers property is used to set the 'Content-Type' to 'application/json', which tells the server that the request body contains JSON data. The body property contains the JSON stringified version of your data. If you're still getting a 400 bad request error, it might be due to the server not accepting the request for some reason. This could be due to the server expecting different data, or there might be an issue with the server itself. You might want to check the API documentation or reach out to the API provider for more information. Sources: - Voiceflow Fetch API
plain-purple
plain-purpleOP2y ago
how do you add this into the Form Data of the Body?
Steve B. | IntelleSync.ai
You need to capture the number in a variable then use 'form data' in your body to send the info. similar to this:
No description
plain-purple
plain-purpleOP2y ago
thanks for your reply. yeah, I've done that for the rest and they work perfectly. But the only one that I am struggling with has an array that i need to follow from a documentation and I can't seem to figure out how to put them together in the Form Data.
No description
plain-purple
plain-purpleOP2y ago
thoughts @NiKo | Voiceflow @Daniel ?
Steve B. | IntelleSync.ai
Right gotcha, You need to send the array in another api step with raw body, you can't mix and match. Do it like this:
No description
No description
Steve B. | IntelleSync.ai
{
"patient_phone_numbers": [
{
"phone_type": "Mobile",
"number": "0-123-456-78"
}
]
}
{
"patient_phone_numbers": [
{
"phone_type": "Mobile",
"number": "0-123-456-78"
}
]
}
plain-purple
plain-purpleOP2y ago
@Steve B. | IntelleSync.ai Although I had to send another call as a Patch API request, that worked like a charm. Thanks, Steve!
Steve B. | IntelleSync.ai
Great glad it worked out!

Did you find this page helpful?