Integrating RingCentral FaxOut API using C#

1.4k views Asked by At

Hi how are you? I'm trying to use the FaxOut API:

http://service.ringcentral.com/faxoutapi/

That's the whole documentation about the api. Basically I need to send an HTTP POST with some data.

This is my code but I can't manage to make it work, please tell me if there's something I'm not seeing.

string URLAuth = "https://service.ringcentral.com/faxapi.asp";
WebClient webClient = new WebClient();
var formData = new NameValueCollection();
formData["Username"] = "2487955151";
formData["Password"] = "mypassword";
formData["Recipient"] = "12485974888";
formData["Coverpagetext"] = "Some random text";
formData["Resolution"] = "High";
byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData);
string resultAuthTicket = Encoding.UTF8.GetString(responseBytes);
webClient.Dispose();

return resultAuthTicket;

Thank you very much!

3

There are 3 answers

0
Grokify On

Your code probably isn't working because WebClient.UploadValues() is likely creating and sending a request with the content type set to application/x-www-form-urlencoded while the API requires multipart/form-data. multipart/form-data is a popular content type when sending files.

Here is some working C# code that uses System.Net.Http (and System.IO) to send a multipart/form-data request.

string url = "https://service.ringcentral.com/faxapi.asp";

var data = new MultipartFormDataContent();
data.Add(new StringContent("16501112222"), "username");
data.Add(new StringContent("mypassword"), "password");
data.Add(new StringContent("16501113333"), "recipient");
data.Add(new StringContent("RingCentral FaxOut API using C#"), "coverpagetext");
data.Add(new ByteArrayContent(File.ReadAllBytes("C:\\path\\to\\test.pdf", "attachment", "test.pdf");

var client = new HttpClient();
var response = client.PostAsync(new Uri(url), data).Result;
if (response.IsSuccessStatusCode)
{
    var responseContent = response.Content;
    var responseString = responseContent.ReadAsStringAsync().Result;
    Console.WriteLine(responseString);
}

You can also use the broader RingCentral Platform API which covers fax and more.

0
risnic On

I've integrated the Popfax service which also provides Fax APIs http://www.popfax.com/index.php?pop=corporate&corp=free_api It works perfectly with our application. I'm sure it will with your software too. The only condition is to have a clear code.

0
Jose Saiz On

Using the ncToolControls ASP.NET

.aspx:

<%@ Register Assembly="ncToolControls" Namespace="ncToolControls" TagPrefix="nc" %>

<nc:FaxService ID="fsCtrl" AddCloseButton="true" CssClass="mobilestyle_input" Width="620px" runat="server" />  
<p align="center"><asp:Literal ID="lit_Message" runat="server"></asp:Literal></p>              

Codebehind .cs

protected void Page_Init(object sender, EventArgs e)
{
    this.fsCtrl.btnCloseFax.Click += new EventHandler(btnCloseFaxScreen_Click);
}
protected void Page_Load(object sender, EventArgs e)
{

    this.fsCtrl.eFaxServer_Name = "rcfax.com";
    this.fsCtrl.Host_Server_Name = "smtp.domain.com";
    this.fsCtrl.Assiged_Email = "Authenticated Email Goes Here";
    this.fsCtrl.AssigedEmail_Password = "Password Goes Here";        
    this.fsCtrl.HostServer_PortNumber = 25;
    this.fsCtrl.HostServerRequireAuthentication = false;
    this.fsCtrl.HostServerRequireSSL = false;
    this.fsCtrl.HostServerRequiresInternationalDigit = false;
    this.fsCtrl.Company_FaxNumber = "12125555555";
    this.fsCtrl.FaxOut_FolderPath = "~/faxout/";  //- Folder must be valid path in Virtual Directory


    if (!Page.IsPostBack)
    {

    }
    btnSave_Click(sender, e);                
}

Download the Sample and Control here http://www.netstair.net/download/RingCentral-Fax.zip