question

Josh Blevins avatar image
Josh Blevins asked Phong Vu answered

PHP Download fax attachment

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...)

rest apifax
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered

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;
            }
        }
    }
  }
}
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys