Fax attachments download using C#

  • 1
  • Question
  • Updated 4 weeks ago
Could you help me with RingCentral Fax API.
I need C# code to download fax attachments . I'am using sandbox account and I found this API in APi Explorer /restapi/v1.0/account/{accountId}/extension/{extensionId}/message-store/{messageId}/content/{attachmentId}
Photo of zgrada zgrada

zgrada zgrada

  • 90 Points 75 badge 2x thumb

Posted 4 weeks ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
Photo of zgrada zgrada

zgrada zgrada

  • 90 Points 75 badge 2x thumb
Hi, I have another problem. Filename is always null. I need filename with extension.
In this case filename is NULL

rc = new RestClient(RingCentralAppKey, RingCentralAppSecretKey,false);
                await rc.Authorize(RingCentralUsername, RingCentralExtension, RingCentralPassword);
                var account = rc.Restapi().Account();
                var extension = account.Extension();
              
                var response = await extension.MessageStore().List();
                var messages = response.records;
                // fax
                var message = messages.Where(m => m.type == "Fax" && m.messageStatus != "SendingFailed" && m.attachments != null && m.attachments.Length > 0);
                foreach (var m in message)
                {
                    var messageResponse = await extension.MessageStore(m.id).Content(m.attachments[0].id).Get();
                    var content = messageResponse.data;
                   
                    var file = new DocumentModel
                    {
                        FileName = m.attachments[0].filename,//this is null
                        FileContent = content
                    };
                }
 
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
I think all of them are of ".pdf" extension, regardless of their original format.  This is because before sending the fax, RingCentral server will pre-render the content to PDF format. So the receiver side always get PDF files.

Let me double check though.
Photo of zgrada zgrada

zgrada zgrada

  • 90 Points 75 badge 2x thumb
Please check for filename also.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,108 Points 5k badge 2x thumb
If what I said above is true, there won't be a reasonable filename.

Because you might send multiple files in a single fax, and those files are merged and rendered to a single pdf file. In such case, what is the filename?  It could be whatever.pdf  because there isn't a one-one mapping from original files to pdf file anyway.
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,802 Points 5k badge 2x thumb
When I inspect the attachment:

{ id: 1111,
      uri:
       'https://media.devtest.ringcentral.com/restapi/v1.0/account/111/extension/222/message-sto...',
      type: 'RenderedDocument',
      contentType: 'application/pdf' }

You can see that type is RenderedDocument

The attachment is not the original file from the fax sender.  And it might be the result of the merging of multiple files.

There is no name for the attachment file. We only know that it's a PDF.