Download Mp3 Recording using PHP SDK
Tags: call recording
Apr 18, 2022 at 10:19am • 1 replies • 0 likes
Luis Tejeda
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:
RingCentral\SDK\Http\ApiResponse Object
(
[
_jsonAsArray:protected
] =>
[
_jsonAsObject:protected
] =>
[
_multiparts:protected
] =>
[
_response:protected
] => GuzzleHttp\Psr7\Response Object
(
[
reasonPhrase:GuzzleHttp\Psr7\Response:private
] => OK
[
statusCode:GuzzleHttp\Psr7\Response:private
] => 200
[
headers:GuzzleHttp\Psr7\Response: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:GuzzleHttp\Psr7\Response: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:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #72 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( )
)
)
[_request:protected] => GuzzleHttp\Psr7\Request Object ( [method:GuzzleHttp\Psr7\Request:private] => GET [requestTarget:GuzzleHttp\Psr7\Request:private] => [uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object ( [scheme:GuzzleHttp\Psr7\Uri:private] => https [userInfo:GuzzleHttp\Psr7\Uri:private] => [host:GuzzleHttp\Psr7\Uri:private] => platform.devtest.ringcentral.com [port:GuzzleHttp\Psr7\Uri:private] => [path:GuzzleHttp\Psr7\Uri:private] => /restapi/v1.0/account/~/recording/11074662005/content [query:GuzzleHttp\Psr7\Uri:private] => [fragment:GuzzleHttp\Psr7\Uri:private] => [composedComponents:GuzzleHttp\Psr7\Uri:private] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/recording/11074662005/content )
[headers:GuzzleHttp\Psr7\Request: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:GuzzleHttp\Psr7\Request:private] => Array ( [content-type] => content-type [accept] => accept [authorization] => Authorization [user-agent] => User-Agent [rc-user-agent] => RC-User-Agent [host] => Host )
[protocol:GuzzleHttp\Psr7\Request:private] => 1.1 [stream:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #70 [size:GuzzleHttp\Psr7\Stream:private] => 0 [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( )
)
)
)
[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:GuzzleHttp\Psr7\Response: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:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #72 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( )
)
)
[_request:protected] => GuzzleHttp\Psr7\Request Object ( [method:GuzzleHttp\Psr7\Request:private] => GET [requestTarget:GuzzleHttp\Psr7\Request:private] => [uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object ( [scheme:GuzzleHttp\Psr7\Uri:private] => https [userInfo:GuzzleHttp\Psr7\Uri:private] => [host:GuzzleHttp\Psr7\Uri:private] => platform.devtest.ringcentral.com [port:GuzzleHttp\Psr7\Uri:private] => [path:GuzzleHttp\Psr7\Uri:private] => /restapi/v1.0/account/~/recording/11074662005/content [query:GuzzleHttp\Psr7\Uri:private] => [fragment:GuzzleHttp\Psr7\Uri:private] => [composedComponents:GuzzleHttp\Psr7\Uri:private] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/recording/11074662005/content )
[headers:GuzzleHttp\Psr7\Request: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:GuzzleHttp\Psr7\Request:private] => Array ( [content-type] => content-type [accept] => accept [authorization] => Authorization [user-agent] => User-Agent [rc-user-agent] => RC-User-Agent [host] => Host )
[protocol:GuzzleHttp\Psr7\Request:private] => 1.1 [stream:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #70 [size:GuzzleHttp\Psr7\Stream:private] => 0 [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( )
)
)
)
1 Answer
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 RingCentral\SDK\SDK($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 (\RingCentral\SDK\Http\ApiException $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.\n"); $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.
0
Byrne Reese on Apr 19, 2022 at 9:28am • 0 likes
@Luis Tejeda If this answers your question, it would be great if you could accept this answer to help other developers!
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder