I am trying to send a media message via Twilio conversations api. In the documentation it shows and example using cURL like this below
curl -u "<account_sid>:<account_secret>" -X POST https://conversations.twilio.com/v1/Conversations/<conversation_sid>/Messages -d MediaSid=<media_sid>
Here is a link to the docs, its at the bottom of the page when scrolling down look for "Using Media Messaging via the Conversations REST API"
I am using Node.js for backend so I need to convert this cURL to an axios post request. Note: in the above example the url in the docs shows https://conversations.twilio.com/v1/Conversations/<conversation_sid>/Messages but I need to do the url below because I am using subaccounts. The solution below is giving me the error "Message body not provided"
data: {
code: 50503,
message: 'Message body not provided',
more_info: 'https://www.twilio.com/docs/errors/50503',
status: 400
}
await axios({ // post request to create media message via conversations REST api
url:`https://conversations.twilio.com/v1/Services/${convoServiceSid}/Conversations/${stringSenderId}/Messages`,
method:"POST",
headers: {
'Content-Type': 'x-www-form-urlencoded'
},
auth: { username: subActServiceSid, password: subActAuthToken },
body: new URLSearchParams({
MediaSid: 'ME58052d0b6e178ace30a0dbb617ffec2c'
})
}).then(res => {
console.log("res from first post request to twilio with fileData", res.data)
})