Skip to main content

Having trouble getting fax attachment using the following code.


$rcsdk = new RingCentral( $CLIENT_ID, $CLIENT_SECRET, "https://platform.ringcentral.com" );
$platform = $rcsdk->platform();

try {
$platform->login(["jwt" => $JWT_TOKEN]);
}catch (ApiException $e) {
// Getting error messages using PHP native interface
print 'Expected HTTP Error: ' . $e;
exit ("Error message: " . $e->apiResponse->response()->error() . PHP_EOL);
}

$accountId = '######';

$extensionId = '#####';

$messageId = '#####';

$attachmentId = '#####';

$queryParams = array(
'contentDisposition' => 'Inline'
);

$r = $platform->get("https://media.ringcentral.com/restapi/v1.0/account/{$accountId}/extension/{$extensionId}/message-store/{$messageId}/content/{$attachmentId}", $queryParams);


Error Received


Client error: `GET https://media.ringcentral.com/restapi/v1.0/account/#######/extension/#####/message-store/######/content/#####?contentDisposition=inline` resulted in a `400 Bad Request` response: { "errorCode" : "InvalidParameter", "message" : "Parameter [contentDisposition] value is invalid.", "errors" : [ { (truncated...)

I am not sure about your code. This code works for me. Can you try it

function read_message_store_fax(){
global $platform;
$params = array(
'dateFrom' => '2023-10-01T23:59:59.999Z',
'dateTo' => '2023-10-20T23:59:59.999Z',
'messageType' => 'Fax'
);
$resp = $platform->get('/account/~/extension/~/message-store', $params);
// Limit API call to ~40 calls per minute to avoid exceeding API rate limit.
$timePerApiCall = 2.1;
foreach ($resp->json()->records as $record){
if (isset($record->attachments)){
foreach($record->attachments as $attachment){
$fileName = $attachment->id . "_fax_attachment.";
$fileNameExt = preg_split("/[/]/", $attachment->contentType, -1);
$fileName .= $fileNameExt[1];
try {
$res = $platform->get($attachment->uri);
$start = microtime(true) * 1000;
file_put_contents($fileName, $res->raw());
$end = microtime(true) * 1000;
$time = ($end - $start);
if($time < $timePerApiCall) {
sleep($timePerApiCall-$time);
}
}catch (ApiException $e) {
$message = $e->getMessage();
print 'Expected HTTP Error: ' . $message . PHP_EOL;
}
}
}
}
}

Reply