Copy link to clipboard
Copied
I am trying to use Twilio to get rid of our fax machine (why do they still exist?!?). I've got inbound fax working but not outbound. They have examples for several languages here but no CF. I tried using their CURL example and converting it to CF but can't get it to work.
CURL:
curl -X POST https://fax.twilio.com/v1/Faxes \
--data-urlencode "From=+15017122661" \
--data-urlencode "To=+15555555555" \
--data-urlencode "MediaUrl=https://example.com" \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
CF:
<cfhttp method = "post" result="result" url = "https://fax.twilio.com/v1/Faxes" username = "#session.TwilioAccountSID#" password = "#Session.TwilioAuthToken#">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type = "body" encoded="no" value = " ""to=+15083930000"", ""from=+15086580000"", ""mediaUrl=http://someurl.me/faxtest.pdf"" ">
</cfhttp>
<cfdump var="#result#">
I get the following error:
{"code": 20001, "message": "Missing required parameter To in the post body", "more_info": "https://www.twilio.com/docs/errors/20001", "status": 400}. The URL says: One or more parameters you sent the REST API were not recognized and were ignored.
Appreciate any help!
Gary
Posting how I got it to work in case anyone else needs the code in the future.
<cfhttp method="post" result="result" url="https://fax.twilio.com/v1/Faxes" username="#session.TwilioAccountSID#" password="#Session.TwilioAuthToken#">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="formfield" name="From" value="+15086580000">
<cfhttpparam type="formfield" name="To" value="+15083930000">
<cfhttpparam type="formfield" name="MediaUrl" value="http:
Copy link to clipboard
Copied
Have you considered using a pre-existing ColdFusion library?
ColdFusion-Twilio-Library
https://github.com/jasonfill/ColdFusion-Twilio-Library
If this doesn't work for you or you are unable to extract the logic, I could write something up. (Although to be honest, I've used CURL with ColdFusion when posting to the Twilio API before.)
Copy link to clipboard
Copied
Wish I knew that the library existed before I wrote everything from scratch. It's based on their old API but still would have been helpful.
Copy link to clipboard
Copied
Posting how I got it to work in case anyone else needs the code in the future.
<cfhttp method="post" result="result" url="https://fax.twilio.com/v1/Faxes" username="#session.TwilioAccountSID#" password="#Session.TwilioAuthToken#">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="formfield" name="From" value="+15086580000">
<cfhttpparam type="formfield" name="To" value="+15083930000">
<cfhttpparam type="formfield" name="MediaUrl" value="http://someurl/testfax.pdf">
<cfhttpparam type="formfield" name="StatusCallback" value="http://soneurl/webhooks-sendresults.cfm" />
</cfhttp>
The StatusCallBack is form data. <cfdump var=#form#>
<cfdump var="#result#">
Copy link to clipboard
Copied
Curl is fine. The following single line of code works when you run it on the command-line.
curl --data-urlencode "From=+15017122661" --data-urlencode "To=+15555555555" --data-urlencode "MediaUrl=https://example.com" -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token" https://fax.twilio.com/v1/Faxes
Copy link to clipboard
Copied
Another example. Here I use the Curl binary for 64Bit Windows. I installed it at C:\bin\curl-7.73.0-win64\bin\curl.exe"
<cfexecute name="C:\bin\curl-7.73.0-win64\bin\curl.exe"
arguments='--data-urlencode "From=+15017122661" --data-urlencode "To=+15555555555" --data-urlencode "MediaUrl=https://example.com" -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token" https://fax.twilio.com/v1/Faxes'
outputfile="#expandPath('.')#\Output.html"/> <!--- Output to HTML file in current folder --->