I have some code to download a recording from Twilio
getRecordingMedia: function (recordingId) {
var client = new Twilio(config.twillio.apiKey, config.twillio.apiSecret, { accountSid: config.twillio.accountId });
var uri = `https://video.twilio.com/v1/Recordings/${recordingId}/Media`;
var response = client.request({ method: "POST", uri: uri });
var mediaLocation = JSON.parse(response.body).location;
request.get(mediaLocation, (err, res, media) => {
return media;
});
}
I get the following error:
SyntaxError: Unexpected token u in JSON at position 0
I looked at the response object and its actually a promise. So, it seems like the documentation is incorrect in the sense that it doesn't handle the promise "then()"
I went ahead and changed the code to use the promise
var response = client.request({ method: "POST", uri: uri }).then((object) => {console.log(object);});
And I actually have an error logged
{ statusCode: 405, body: '{"code": 20004, "message": "Method not allowed", "more_info": "https://www.twilio.com/docs/errors/20004", "status": 405}' }
I looked at the documentation on the referred link, but it didn't help me much.
Additionally If I open the url https://video.twilio.com/v1/Recordings/${recordingId}/Media in my browser and enter the credentials I get the recording.
So, need help in figuring out if the documentation is incorrect (as to the promise - https://www.twilio.com/docs/api/video/recordings-resource#code-retrieve-a-recording) and why Im getting the error with code 20004.
Thanks