Question

Download Mp3 Recording using PHP SDK

  • 18 April 2022
  • 2 replies
  • 524 views

Im trying to _Dowload a recording via PHP SDK using the next endpoint:

https://platform.devtest.ringcentral.com/restapi/v1.0/account/accountId/recording/recordingId/content

I get the next response but i dont know how to convert this into a base64 or some kind of data, that i can send to front end and download a file:

RingCentralSDKHttpApiResponse Object( [_jsonAsArray:protected] => [_jsonAsObject:protected] => [_multiparts:protected] => [_response:protected] => GuzzleHttpPsr7Response Object ( [reasonPhrase:GuzzleHttpPsr7Response:private] => OK [statusCode:GuzzleHttpPsr7Response:private] => 200 [headers:GuzzleHttpPsr7Response:private] => Array ( [Server] => Array ( [0] => nginx )
[Date] => Array ( [0] => Mon, 11 Apr 2022 05:36:38 GMT )
[Content-Type] => Array ( [0] => audio/mpeg )
[Content-Length] => Array ( [0] => 90513 )
[Connection] => Array ( [0] => keep-alive )
[RCRequestId] => Array ( [0] => 5beabc92-b959-11ec-87c5-005056bb27a8 )
[RoutingKey] => Array ( [0] => SJC12P01PAS01 )
[Accept-Ranges] => Array ( [0] => bytes [1] => bytes )
[Content-Disposition] => Array ( [0] => inline;filename=11074662005.mp3 )
[Content-Language] => Array ( [0] => en-US )
[X-Rate-Limit-Group] => Array ( [0] => heavy )
[X-Rate-Limit-Limit] => Array ( [0] => 10 )
[X-Rate-Limit-Remaining] => Array ( [0] => 9 )
[X-Rate-Limit-Window] => Array ( [0] => 60 )
)
[headerNames:GuzzleHttpPsr7Response:private] => Array ( [server] => Server [date] => Date [content-type] => Content-Type [content-length] => Content-Length [connection] => Connection [rcrequestid] => RCRequestId [routingkey] => RoutingKey [accept-ranges] => Accept-Ranges [content-disposition] => Content-Disposition [content-language] => Content-Language [x-rate-limit-group] => X-Rate-Limit-Group [x-rate-limit-limit] => X-Rate-Limit-Limit [x-rate-limit-remaining] => X-Rate-Limit-Remaining [x-rate-limit-window] => X-Rate-Limit-Window )
[protocol:GuzzleHttpPsr7Response:private] => 1.1 [stream:GuzzleHttpPsr7Response:private] => GuzzleHttpPsr7Stream Object ( [stream:GuzzleHttpPsr7Stream:private] => Resource id #72 [size:GuzzleHttpPsr7Stream:private] => [seekable:GuzzleHttpPsr7Stream:private] => 1 [readable:GuzzleHttpPsr7Stream:private] => 1 [writable:GuzzleHttpPsr7Stream:private] => 1 [uri:GuzzleHttpPsr7Stream:private] => php://temp [customMetadata:GuzzleHttpPsr7Stream:private] => Array ( )
)
)
[_request:protected] => GuzzleHttpPsr7Request Object ( [method:GuzzleHttpPsr7Request:private] => GET [requestTarget:GuzzleHttpPsr7Request:private] => [uri:GuzzleHttpPsr7Request:private] => GuzzleHttpPsr7Uri Object ( [scheme:GuzzleHttpPsr7Uri:private] => https [userInfo:GuzzleHttpPsr7Uri:private] => [host:GuzzleHttpPsr7Uri:private] => platform.devtest.ringcentral.com [port:GuzzleHttpPsr7Uri:private] => [path:GuzzleHttpPsr7Uri:private] => /restapi/v1.0/account/~/recording/11074662005/content [query:GuzzleHttpPsr7Uri:private] => [fragment:GuzzleHttpPsr7Uri:private] => [composedComponents:GuzzleHttpPsr7Uri:private] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/recording/11074662005/content )
[headers:GuzzleHttpPsr7Request:private] => Array ( [Host] => Array ( [0] => platform.devtest.ringcentral.com )
[content-type] => Array ( [0] => application/json )
[accept] => Array ( [0] => application/json )
[Authorization] => Array ( [0] => bearer U0pDMTJQMDFQQVMwMHxBQUI1aUNTVnJsempDeE04aXpPaC1DUXZianU4a1hfYTg0ejQtMmtZRS1ZSVM1ZmpYMlhJUFM0V1NNdkM5Y3hEUkpBS3MxdDlGZnJkMDUxSXg1NzRmZURpajBhQWh2aEh4Z0dlZ0hZVFdBUmk0Vzg2ak1ZdkJpNUpoN3FjUVcyRjRVLVhQSzFpV0J6cHM2dHNwZklLRV82dnB4b0hRaUxsdGtaR1BURFlnZUpzcllPaEc2bTJOT0xyRHg1RDJWYnZKdi1Bc2JUZHxjclQ3WlF8cDYtaHJheXdQSW5YQm9VNjNHdG80QXxBUQ )
[User-Agent] => Array ( [0] => Unnamed/0.0.0 Windows NT/6.2 PHP/7.4.16 RCPHPSDK/2.2.3 )
[RC-User-Agent] => Array ( [0] => Unnamed/0.0.0 Windows NT/6.2 PHP/7.4.16 RCPHPSDK/2.2.3 )
)
[headerNames:GuzzleHttpPsr7Request:private] => Array ( [content-type] => content-type [accept] => accept [authorization] => Authorization [user-agent] => User-Agent [rc-user-agent] => RC-User-Agent [host] => Host )
[protocol:GuzzleHttpPsr7Request:private] => 1.1 [stream:GuzzleHttpPsr7Request:private] => GuzzleHttpPsr7Stream Object ( [stream:GuzzleHttpPsr7Stream:private] => Resource id #70 [size:GuzzleHttpPsr7Stream:private] => 0 [seekable:GuzzleHttpPsr7Stream:private] => 1 [readable:GuzzleHttpPsr7Stream:private] => 1 [writable:GuzzleHttpPsr7Stream:private] => 1 [uri:GuzzleHttpPsr7Stream:private] => php://temp [customMetadata:GuzzleHttpPsr7Stream:private] => Array ( )
)
)
)

2 replies

Userlevel 1

This PHP sample code should help you read call log and download the call recording if any.

<?php
require('vendor/autoload.php');

$RINGCENTRAL_CLIENTID = "You-App-ClientId";
$RINGCENTRAL_CLIENTSECRET = "You-App-ClientSecret";
$RINGCENTRAL_SERVER = 'https://platform.ringcentral.com';

$RINGCENTRAL_USERNAME = "username";
$RINGCENTRAL_PASSWORD = "passaword";
$RINGCENTRAL_EXTENSION = "extension-number";

$rcsdk = new RingCentralSDKSDK($RINGCENTRAL_CLIENTID, $RINGCENTRAL_CLIENTSECRET, $RINGCENTRAL_SERVER);

$platform = $rcsdk->platform();
try{
  $platform->login($RINGCENTRAL_USERNAME, $RINGCENTRAL_EXTENSION, $RINGCENTRAL_PASSWORD);
  $params = array(
      'dateFrom' => '2022-03-01T23:59:59.999Z',
      'dateTo' => '2022-03-31T23:59:59.999Z'
      );
  $resp = $platform->get('/account/~/extension/~/call-log', $params);
  foreach ($resp->json()->records as $record) {
      if ($record->type == "Voice"){
        if (isset($record->recording)){
          $parts = explode('/', $record->recording->uri);
          $fileName = $parts[count($parts)-1].".mp3";
          download_callrecording_content($record->recording->contentUri, $fileName);
        }
      }
  }
}catch (RingCentralSDKHttpApiException $e) {
      print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL;
}

function download_callrecording_content($contentUri, $fileName){
    global $platform;
    echo ("Save call recording file to the local machine.
");
    $uri = $platform->createUrl($contentUri, array(
          'addServer' => false,
          'addMethod' => 'GET',
          'addToken'  => true
    ));
    file_put_contents($fileName, fopen($uri, 'r'));
}

Let me know if you face problem or kindly accept the answer if it helps.

@Luis Tejeda If this answers your question, it would be great if you could accept this answer to help other developers!

Reply