Question

Response: StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Connection: keep-alive RCRequestId: 56564a9c-9ec3-11ea-9c69-005056af5c03 RoutingKey: IAD01P13PAS06 X-Rate-Limit-Group: medi

  • 28 May 2020
  • 2 replies
  • 3078 views

Here is the code you asked for in this issue.


public async Task<object> Read(FaxReadType faxReadType)
{
        object returnData = null;
        try
        {
            using (RestClient rc = new RestClient(RINGCENTRAL_CLIENTID
                                                , RINGCENTRAL_CLIENTSECRET
                                                , IS_PRODUCTION))
            {
                TokenInfo tokenInfo = await rc.Authorize(RINGCENTRAL_USERNAME
                                                        , RINGCENTRAL_EXTENSION
                                                        , RINGCENTRAL_PASSWORD);

                if (rc.token.access_token.Length > 0)
                {
                    switch (faxReadType)
                    {
                        case FaxReadType.ReadContent:
                            ReadMessageContentParameters read = new ReadMessageContentParameters
                            {
                                contentDisposition = "Attachment"
                            };

                            returnData = await rc.Restapi().Account().Extension()
                                            .MessageStore(messageId).Content(attachmentId).Get(read);
                            break;

                        case FaxReadType.ReadMessage:
                            returnData = await rc.Restapi().Account().Extension()
                                            .MessageStore(messageId).Get();
                            break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            //Log exception in DB
        }
        return returnData;
    }



2 replies

That is just a wrong way to read the attachment of a fax message. I don't know where you get the "messageId" from. Is you intention just to read the attachment and save to a local file?

This is an example of how to read message store message's attachment.

private async Task read_message_store_by_id(string messageId)
{
  await rcsdk.Authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD);
  if (rcsdk.token.access_token.Length > 0)
  {
    var response = await rcsdk.Restapi().Account().Extension().MessageStore(messageId).Get()
    if (response.attachments != null)
    {
      var path = "fax_content/";
      System.IO.Directory.CreateDirectory(path);
      foreach (var attachment in response.attachments)
      {
        var fileName = response.attachments[0].id + "_fax_attachment";
        var fileNameExt = attachment.contentType.Split('/');
        fileName = String.Format("{0}.{1}", fileName, fileNameExt[1]
        Console.WriteLine(fileName);
        var start = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
        var res = await rcsdk.Restapi().Account().Extension().MessageStore(response.id.ToString()).Content(attachment.id.ToString()).Get();
        using (BinaryWriter writer = new BinaryWriter(System.IO.File.Open(path + fileName, FileMode.Create)))
        {
          writer.Write(res);
          writer.Flush();
          writer.Close();
        }
        Console.WriteLine("Done");
     }
   }
  }
}


Reply