Is there a simple Node.js code sample for downloading call recordings?

  • 1
  • Question
  • Updated 8 months ago
I'm using node.js to pull down call logs. Now I would like to download call recordings. Is there a simple JavaScript code sample for me to start from?
Photo of Don Jackson

Don Jackson

  • 160 Points 100 badge 2x thumb

Posted 8 months ago

  • 1
Photo of Phong Vu

Phong Vu, Devangelist

  • 2,256 Points 2k badge 2x thumb
Photo of Don Jackson

Don Jackson

  • 160 Points 100 badge 2x thumb
Thanks Phong Vu. That gives me a good start.
When I log in, then run:

rcsdk.platform().get('/restapi/v1.0/account/~/recording/<recording id here>').then(function(res) {
    return res.response().buffer(); // we are accessing Node Fetch's Response
}).then(function(buffer) {
 
}

I get the error:

"body used already for: https://platform.ringcentral.com/restapi/v1.0/account/~/recording/<recording id>"


When I put in an invalid recording id it tells me that callRecordingId is not found, but when I put a valid id in it gives me the above error

Is my get not structured properly?
Photo of Phong Vu

Phong Vu, Devangelist

  • 2,146 Points 2k badge 2x thumb
Hi Don,

The example code is not precise.

Use my test code below. Assumed that the record is an item in the records array from the response. Always check if the recording is available

if (record.recording != undefined) {
    recordingId = record.recording.id
    rcsdk.platform().get(record.recording.contentUri)
    .then(function(res) {
        return res.response().buffer();
    })
    .then(function(buffer) {
        console.log("buffer")
        fs.writeFileSync(recordingId + '.mp3', buffer);
    })
    .catch(function(e){
        throw e
    })
}

You can also check the record content type to define the audio file name extension.

Hope this helps,
+ Phong