News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
PHP Download fax attachment
Tags: fax, rest api
Dec 22, 2023 at 10:57am   •   1 replies  •  0 likes
Josh Blevins

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

1 Answer
answered on Dec 22, 2023 at 1:00pm  

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

 0



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us