Internal Server Error - Sending Multiple Fax C# .NET

  • 1
  • Problem
  • Updated 4 weeks ago
  • (Edited)
Not able to send the multiple fax using following code: 

Getting this  Error,

{


  "message" : "Internal Server Error. Consult RC Support.",

  "eventId" : "0eac3cde-a7b6-11e8-a382-005056bb26b9"

}

---------------------------------------------------------------------------------------
We have used following code.







Any help will be appreciated. Thank you! 


Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
  • SAD, that we are not able to do anything . . .

Posted 1 month ago

  • 1
Photo of John Wang

John Wang, Official Rep

  • 5,496 Points 5k badge 2x thumb
Can you make any other API calls successful? For example, calling the extension info endpoint.

I'm wondering if this is an issue with the PDF file itself.

Can you try the example PDF file here (click the "Download"):

https://github.com/grokify/go-ringcentral/blob/master/examples/fax_send/test_file.pdf

If that works, can you provide an example PDF that is failing. If so, join our Glip team here:

https://glipped.herokuapp.com/
(Edited)
Photo of Anton Nikitin

Anton Nikitin, Official Rep

  • 2,904 Points 2k badge 2x thumb
Arpit, I have found your request in server logs and sent it to Dev Team for investigation. Stay tuned.
Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
Hii Nikitin,

Do we have any update on this Internal Server Error??
(Edited)
Photo of Anton Nikitin

Anton Nikitin, Official Rep

  • 2,904 Points 2k badge 2x thumb
Arpit, we cannot reproduce it. Apparently the HTTP request body you are sending is malformed. Can you trace HTTP request so we can see the entire body as it is sent to us? It would help a lot.
Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
There you go,


class Program
    {
        static void Main(string[] args)
        {
            GetRingCentralAPIToken();
        }
        public static void GetRingCentralAPIToken()
        {
            string resultToken = string.Empty;
            var client = new RestClient("https://platform.devtest.ringcentral.com/restapi/oauth/token");
            var request = new RestRequest(Method.POST);
            request.AddHeader("postman-token", "0488f4ed-13da-25d3-9f7f-d2243be3089b");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddHeader("accept", "application/json");
            request.AddHeader("authorization", "Basic bEZvRU5BQVFSMW1RT2RtZWpYb2xvZzpNQmxKLWl5RFNIdUIxRE5vVnZpRXpnU1RncFNwdHVSdWFBUWRpdWpqQzFBUQ==");
            request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&username=16167946751&extension=101&password=*****", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            string response_code = response.Content.ToString();
            var details = JObject.Parse(response.Content);
            resultToken = details["access_token"].ToString();
            PostFax("12052089553", resultToken, 1);
        }

        public static void PostFax(string getFaxNumber, string getToken, int transactionID)
        {

            string getDate = DateTime.UtcNow.ToString("o");
            var client = new RestClient("https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax");
            var request = new RestRequest(Method.POST);
            request.AddHeader("postman-token", "8ca9f9bc-82de-60ef-ffb1-98ac03e017ce");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("authorization", "bearer " + getToken);


            var pdfFile = File.ReadAllBytes("c:\\Testing PFD.pdf");

            request.AddHeader("content-type", "multipart/mixed; boundary=Boundary_1_14413901_1361871080888");
            request.AddParameter("multipart/mixed; boundary=Boundary_1_14413901_1361871080888", "--Boundary_1_14413901_1361871080888\r\nContent-Type: application/json\r\n\r\n{\"to\":[{\"phoneNumber\":\"" + getFaxNumber + "\"}],\r\n \"faxResolution\":\"High\",\r\n \"sendTime\":\"" + getDate + "\"}\r\n\r\n--Boundary_1_14413901_1361871080888\r\nContent-Disposition: form-data; name=\"attachment\"; filename=\"Testing PFD.pdf\"\r\nContent-Transfer-Encoding: " + pdfFile + "\r\nContent-Type: application/pdf\r\n\r\n\r\n--Boundary_1_14413901_1361871080888--\r\n", ParameterType.RequestBody);



            IRestResponse response = client.Execute(request);
            string response_code = response.Content.ToString();
            var details = JObject.Parse(response.Content);

        }
Photo of Anton Nikitin

Anton Nikitin, Official Rep

  • 2,904 Points 2k badge 2x thumb
I think you can't get correct multipart/mixed body with this code. I recommend you to use multipart/form-data as described here in Pattern #3 : https://developer.ringcentral.com/api-docs/latest/index.html#!#RefCreateFaxMessage to form request body like this:

POST /restapi/v1.0/account/691748004/extension/691748004/fax HTTP/1.1
Content-Type: multipart/form-data; boundary=Boundary_14_2952358_1361963763144

--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="coverPageText"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain


--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="coverIndex"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

2
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="faxResolution"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

High
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="sendTime"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

2030-03-19T08:00:00.000Z
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="isoCode"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

GB
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="to"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

+18774880001
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="to"
Content-Transfer-Encoding: 8bit
Content-Type: text/plain

+18004778345
--Boundary_14_2952358_1361963763144
Content-Disposition: form-data; name="attachment"
Content-Transfer-Encoding: binary
Content-Type: text/plain

attachment1

--Boundary_14_2952358_1361963763144--

You should use RestRequest.AddFile to add your file as attachment as described here: https://blog.tyrsius.com/restsharp-file-upload/

I am not C# expert so it is just my guess. 
 
Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
Thank you: it got resolved. Your help is appreciated. 
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,008 Points 5k badge 2x thumb
Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
I think this should work out . . .
Photo of Tyler Long

Tyler Long, Official Rep

  • 7,008 Points 5k badge 2x thumb
Let me know if it doesn't work. I am always ready to help.
Photo of Arpit Patel

Arpit Patel

  • 172 Points 100 badge 2x thumb
We are still working on it: hopefully be able to figured this one out.
Photo of Venkatesa Prasanna

Venkatesa Prasanna

  • 60 Points
Still we are having a issue.
Because we are having Visual Studio 2015 and Framework 4 used in our application.

1. We tried to install Ringcentral.Client from Nuget, we received the below message.

"Severity Code Description Project File Line Suppression State
Error  Could not install package 'Flurl.Http 2.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.  "

Please find attachment.



2. Also We have tried to install RingCentralSDK from Nuget and it is installed successfully. But After installed we tried to build our application, it is showing the following error.

Please find attachment.


So I request you that please provide us the source code which is support for .net framework 4.

We just wanted to use Fax API only to send multiple attachment and retrieve response only.

Thanks for your help.
Photo of Arpit Patel

Arpit Patel

  • 142 Points 100 badge 2x thumb
Yes, you are right . . .

Upgrading the .Net Framework is a huge task for us as our application is quite big.
But is there any other way we can use FAX APIs in our application without using RingCentral.Client SDK ??

Please look at the problem of main thread: it is a Internal Server Error . . .
We just trying to resolve that one only.

** only fax api we wants to use in out application nothing else

Your response will be appreciated.

Thank you!
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,614 Points 5k badge 2x thumb
Actually there is an easy workaround. It is possible to send fax via curl: https://medium.com/ringcentral-developers/use-curl-to-access-ringcentral-platform-api-d4710fe68fa4


curl is just a command line utility which has windows version: https://curl.haxx.se/windows/


You can use C# to invoke curl: https://stackoverflow.com/questions/1469764/run-command-prompt-commands


Please let me know whether the workaround above works for you.
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,614 Points 5k badge 2x thumb
Or you can use this SDK https://github.com/ringcentral/ringcentral-csharp

It is deprecated. But it might be the only one which supports .NET 4.0

Fax sending sample: https://github.com/ringcentral/ringcentral-csharp/blob/master/RingCentral.Test.Real/MessageTest.cs#L...
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,614 Points 5k badge 2x thumb
If you don't want to use any SDK, you can reference how we built the multipart content: https://github.com/ringcentral/ringcentral-csharp/blob/master/RingCentral/Http/Request.cs#L124-L136
Photo of Arpit Patel

Arpit Patel

  • 142 Points 100 badge 2x thumb
Thank you: issue got resolved.