question

PCIC Team avatar image
PCIC Team asked PCIC Team commented

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

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


404
1 |1000

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

Phong Vu avatar image
Phong Vu answered PCIC Team commented

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?

1 comment
1 |1000

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

PCIC Team avatar image PCIC Team commented ·


The messageId is captured when a new fax is sent or received using the API and the webhooks.

We used the code from the API reference to read the message and/or attachement. If the usage is wrong, then please provide the correct piece of code to use.

0 Likes 0 ·
1590687858275.png (155.5 KiB)
Phong Vu avatar image
Phong Vu answered PCIC Team commented

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


1 comment
1 |1000

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

PCIC Team avatar image PCIC Team commented ·

There is not much difference in the way we are doing it and your way answer. You are saving the file and we are displaying the contents on the UI.

We are reading the message using the messageId like your code, like in your code.

var response = await rcsdk.Restapi().Account().Extension().MessageStore(messageId).Get();

We are reading the attachment using attachementId. The only change in your code is response.id.ToString() is nothing but the messageId that we are passing to our function.

var res = await rcsdk.Restapi().Account().Extension().MessageStore(response.id.ToString()).Content(attachment.id.ToString()).Get();

The only difference that we see is not using the following piece of code to be sent as a part of the reading the attachment. Why is it in the API documentation?

ReadMessageContentParameters read = new ReadMessageContentParameters
{
    contentDisposition = "Attachment"
};

Also, this does not answer the issue of 404 or 503 error that we are still facing.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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