question

kevin-truong72 avatar image
kevin-truong72 asked Anirban answered

How to attach PDF to a fax message?

I am trying to attach a pdf to a fax that i am sending using code below


HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);

Stream rs = wr.GetRequestStream();

StreamReader sr = new StreamReader(filepath);

byte[] fileStream = ReadFully(sr.BaseStream);

rs.Write(fileStream, 0, fileStream.Length);

sr.Close();


public static byte[] ReadFully(Stream input)

{


byte[] buffer = new byte[20 * 1024];

using (MemoryStream ms = new MemoryStream())

{


if (input != null)

{


int read;

while ((read = input.Read(buffer, 0, buffer.Length)) > 0)

{


ms.Write(buffer, 0, read);

}

}

return ms.ToArray();

}

}


I get back the response that Fax was Queued, but when I receive fax it is only default cover page. This mean the binary data was not attached. What am I missing?

fax
1 |3000

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

John Wang avatar image
John Wang Deactivated answered
To send a fax you'll need to create a multipart/mixed request and add each PDF as an attachment. You can either send the raw bytes or base 64 encode the file.

The easiest way to do this with C# is to use our new (alpha) SDK which is available on Nuget and GitHub:
You can get the package from Nuget and follow the fax instructions under "Send Fax" on the GitHub link.

There are example request bodies on the community Ruby SDK documentation here if you're interested in what the raw requests look like:
1 |3000

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

kevin-truong72 avatar image
kevin-truong72 answered
Thanks John for your quick reply. Good to hear about .Net SDK, I am looking into it now as my application is configured for Sandbox so I am using  
https://platform.devtest.ringcentral.com  
as apiEndPoint and when trying to Authenticate I am getting response

{
  "error" : "invalid_grant",
  "error_description" : "Invalid resource owner credentials."
}

Do I have to give permission for SDK to connect to my application somewhere?
1 |3000

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

John Wang avatar image
John Wang Deactivated answered John Wang Deactivated commented
That error typically indicates that the username / extension / password credentials supplied are incorrect. You should make sure that the credentials you are using are associated with your Sandbox Account.

The Sandbox Account Main Company Number for this account is located in your Developer Portal account ( https://developers.ringcentral.com) under Sandbox Accounts. By default, the admin extension, 101, is configured with a password that is emailed to you.

You can test that phone number by logging into the Sandbox Online Account Portal here: https://service.devtest.ringcentral.com.

Let us know if that works.
7 comments
1 |3000

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

kevin-truong72 avatar image kevin-truong72 commented ·
It worked I was passing my Sandbox number as extension as well (I saw somewhere that REST api uses same thing for both account and extension so was just following that) and that was the issue. I wish i knew about .Net SDK sooner but thanks a lot for sharing that and for your help.

As you said this .Net SDK is your alpha version, can I go ahead to Production with this version? When you move to beta or next version will there be any significant changes that can it break things for us on production?
0 Likes 0 ·
John Wang avatar image John Wang ♦♦ commented ·
We are currently in active development of this SDK and the interface is changing. We anticipate moving this out of alpha in a few weeks after which time the interface will be much more stable for backward compatibility purposes.
0 Likes 0 ·
kevin-truong72 avatar image kevin-truong72 commented ·
Thanks John. We decided to wait as you suggested so whenever you release your new version, is it possible for you to send us an email?
0 Likes 0 ·
John Wang avatar image John Wang ♦♦ commented ·
Hi Kevin. The best way to stay up to date on the SDK is to watch / follow the GitHub repo. If you "watch" the repo you should get emails whenever the GitHub project is updated, including the 1.0 release. You can watch the repo by going to the URL below and clicking the "watch" button in the upper right corner.

GitHub URL:  https://github.com/ringcentral/ringcentral-csharp

Let me know how that sounds. Thanks.
0 Likes 0 ·
kevin-truong72 avatar image kevin-truong72 commented ·
Sounds good. Thanks.
0 Likes 0 ·
kevin-truong72 avatar image kevin-truong72 commented ·
Hi John,
It is more than 3 months now and on Github I still see version 0.1.0 for ringcentral-csharp. Is this stable enough that we can use it on our production environment? or should I still wait for version 1.0?
0 Likes 0 ·
John Wang avatar image John Wang ♦♦ commented ·
Hi Kevin,

I answered this on GitHub back in Dec but wanted to answer here as well.

https://github.com/ringcentral/ringcentral-csharp/issues/7

The SDK is stable enough for production use. We are working to close out the issues identified on GitHub for long running subscriptions.

The main difference between the current version and the 1.0 version will be a refactoring of classes and methods to correspond to our SDK reference. If you are okay with a naming change later, then feel free to go ahead and use the existing SDK.
0 Likes 0 ·
Anirban avatar image
Anirban answered

For those who want to use fax API, the fax api support attachments as data which means no data will be passed in body, instead all the data including files and plain text will be pass as an attachment in the api


                
  1. Content-Type: multipart/mixed

The API allows sending a fax message with a multipart request, incorporating two or more parts.

ref: https://developers.ringcentral.com/api-reference#

other examples: https://github.com/grokify/go-ringcentral/tree/master/examples

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