Home > Uncategorized > Send #Faxes via #API using C# @Twilio

Send #Faxes via #API using C# @Twilio


Faxes are still an old technology, and to be honest, I fail to understand how some companies still require them for certain authenticated (signed) documents. There are numerous services online that provide paid-for faxes, like sendfaxes.co.uk 

However, I saw that Twilio offers a FAX API, so if you wanted to add the functionality to your C# application, then here’s some sample code;

const string username = “xxxxx”;
const string password = “zzzzzz”;

var strUrl = “https://fax.twilio.com/v1/Faxes”;
strUrl = string.Format(strUrl, username);
var wc = new WebClient();
wc.Headers[“Content-Type”] = “application/x-www-form-urlencoded”;
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + “:” + password));
wc.Headers[HttpRequestHeader.Authorization] = string.Format(
“Basic {0}”, credentials);

var strResponse = wc.UploadString(strUrl, “To=%2B” + strToNumber +
“&From=%2B” + strFromNumber +
“&MediaUrl=” + strFax);

I tested this against FaxBurner, in order to get a temporary FAX number, and after about 2 minutes the fax arrived.

The Fax I sent was this: http://www.xmlpdf.com/manualfiles/hello-world.pdf – and it arrived in a similar format, but with the grey turned into a pattern of dots, since Faxes are monochrome. (as below)


It is worth noting that during the 2 minutes when the FAX was being sent, it was possible to poll on Twilio for a status update, by calling the url with authentication, and with the SID returned in the JSON – https://fax.twilio.com/v1/Faxes\/{sid}

The status property of the JSON moved from “queued” to “sending” then finally “delivered” – i.e.

“media_sid”: “ME88a43ed8bdf1ddc9dbce3914ceeee7f3”,
“status”: “delivered”,
“direction”: “outbound”,
“from”: “+16193332636”,
“date_updated”: “2017-05-25T11:09:29Z”,
“price”: “-0.035”,
“account_sid”: “AC84d144631d43d12966be8c03e2c6a640”,
“to”: “+18668158879”,
“date_created”: “2017-05-25T11:04:20Z”,
“url”: “https:\/\/fax.twilio.com\/v1\/Faxes\/FXa6503014cfdc71509b9bf9f02cc7976a”,
“sid”: “FXa6503014cfdc71509b9bf9f02cc7976a”,
“duration”: 286,
“num_pages”: 1,
“quality”: “fine”,
“price_unit”: “USD”,
“api_version”: “v1”,
“media_url”: “https:\/\/media.twiliocdn.com\/fax\/AC84d144631d43d12966be8c03e2c6a640\/e5225a49644c2edd383baa803b4db3a2061c7301cdea8b2b600568b5adfa16b326c345334b0b0a8100a5fc608fa58ab330b365830df5308a84a2ec78bc924137?x-amz-security-token=FQoDYXdzEOr%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDHhP4wXa%2F%2BYky2StOCK3A2efy0tyDbg1GlWUU58EVMiK8arQIwL8MuNF0RkNNjeQ7OhI5rEJ8Jt3Gm59qYbBTpS7Ay9RmVNkePDTc19I96r16IZQzBR3G1zlZ4rhZE%2BORofirA3qv2lopLvokhyHj8UNtXMZ73pvWaJ32fcXmvbpkbgc50O8Mjuah84D5pc2w1nI0WlhCQB5btB9bvL5gbavI2ZbHKodUpgA%2FrQilGtEn7fXeO4S4J07Vp5o4LRSzFH7K3HWfgRdZxo3GYxKZqm6WCiR8qk2JQubBNbqJByY4Wb6R4a39OykpkZHPcr6gllDFqrF0fV%2B4%2FyWeukGfvEaEN332LZGJ%2BZj6hLyAWrG5vNtDZNvDr%2BoSwssnXhiu7wQn7syqs6WVCxy5KnmRi6c3PNvsAgAL6RkI%2F2alN7hxexVMxN%2BhnDmuT6c2Wb%2FtEFXJwIxOd1vMWgVIVDX%2FORrxyugIpcyNyDLghRm8cMtCKeED12TpGIdpbHQLPZTBpObPyRluJ4ZYOQkcGfRoFrJxdBPayRawTlLOBaKfY23yMzwWkH9cQKHlvXTGDy6MBrjb3wEVwHu5C4B1WndHIpSfKXPaAMotL%2BayQU%3D&AWSAccessKeyId=ASIAJH4JX2XKGVNEIEFA&Expires=1495717784&Signature=erQay6zd%2BzjBjYGxtf5BoHIiJMo%3D”,
“links”: {
“media”: “https:\/\/fax.twilio.com\/v1\/Faxes\/FXa6503014cfdc71509b9bf9f02cc7976a\/Media”



Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: