I’m working with the Twilio API and need to send an array of URLs in the value of the “MediaUrl” parameter. The API is not accepting the value no matter how I structure the array though. I thought it was a Twilio problem, but now I’m thinking it might be an issue with how I’m setting up the API Connector.
I may be wrong but what I read and understand from the doc is not to send an array but to send the mediaurl parameter multiple time (one for each file)
That is what I though first as well, and so I initially set up the call that way, but it only accepted the first “MediaUrl” parameter it found and simply ignored the rest. From what I understand they want a single MediaUrl “parameter” with multiple “values”. I assumed multiple values means an array, but maybe I’m wrong.
So weird thing about Twilio API, it does not accept a json body in a call. If you send a json body, you get a 400 response saying it is missing required parameters (Because it doesn’t recognize them in the json). So all all API calls have to be sent with the form-data body type.
I got Twilio to accept the call, but turns out you were right and according to Twilio support (and the tests I ran) the multiple Urls need to be sent in separate parameters (not as a list).
So taking this into account, the body looks like this:
This call WORKS, but only if ALL the MediaUrl parameters have a URL in them. If I want to send a message with just one piece of media (instead of 10) I get a error response that the values are null and therefore invalid.
Now, I could create 11 different calls in API connector and call the one with the right number of parameters depending on the number of images being sent from my app, but that’s a bit of a mess. Is there anyway to set up the body so that the MediaUrl parameters are optional the way that you can make them if they are a regular parameter in API connector?
The above works for a file with no spaces, but if the uploaded file contains a space then the API hits an error. I tried finding and replacing any spaces in the URL with %20 or + but Twilio still doesn’t accept it, I get a 400 response that the URL is invalid.
According to their support team sending an encoded URL should work, but somehow the encoded URL I’m sending is get decoded before it gets process by the API.
I found another post with a possible workaround and I wanted to share it with all of you because it works!
If you do a find and replace on the file URLs replacing %20 with %2520 (the %25 is the percent sign in URL encoding land) and then do the delimiter change per AJ’s response, it works like a champ.