How to Send a Fax as a PDF Link

You can use the SignalWire Compatibility APIs to send a fax with a URL that directs to a PDF very easily. Take a look at how to do it below.

Code Breakdown

To run the code snippet, the first thing you will have to do is retrieve your SignalWire Space URL, your Project ID, and an API Token. The latter two of that list can be found under the "API" tab of your SignalWire Space.

#!/bin/sh
#
#
#
project_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
api_token=PTomgthisisareallylongapitokenthatstartswithPT
space_url=example.signalwire.com

Next, you will need to define a fax from number. Please note that the number that the fax is sent from must be a phone number within the associated SignalWire project and be formatted as "+1XXXXXXXXXX".

dial_from=+15559994444

Finally, in the code snippet above, a switch was built asking for the input from the user as to whether or not they wanted to send a fax containing a URL or a test page, which then executes accordingly.
The program asks who you would like to send the fax to, and in the case of a PDF URL, the program also requests the link to the PDF URL.

stage1() {
 while true;do
    read -p "Press (Y) to fax a pdf URL. Press (T) to fax a test page. (yes/test/exit) " yno
    case $yno in
        [Yy]*) stage3;;
        [Tt]*) stage2;;
        [Ee]*) exit 0;;
        [Nn]*) stage2;;
                  *) echo "Done";;
    esac
done
}
stage3() {
echo "Enter the number you want to fax in this format +19998887777"
read -p 'To: ' dial_to
echo "Use a valid URL to a PDF"
read -p 'Define a PDF URL: ' custom_url
command curl https://$space_url/api/laml/2010-04-01/Accounts/$project_id/Faxes.json   -X POST   --data-urlencode "From=$dial_from"   --data-urlencode "To=$dial_to"   --data-urlencode "MediaUrl=$custom_url"   -u "$project_id:$api_token"
}
stage2() {
echo "Enter the number you want to fax in this format +19998887777"
read -p 'To: ' dial_to
command curl https://$space_url/api/laml/2010-04-01/Accounts/$project_id/Faxes.json   -X POST   --data-urlencode "From=$dial_from"   --data-urlencode "To=$dial_to"   --data-urlencode "MediaUrl=https://opensource.apple.com/source/cups/cups-136.9/cups/test/testfile.pdf""   -u "$project_id:$api_token"
}
stage1
exit 0

In both executables where a fax is sent, notice the bash script makes a CURL request, which then sends the fax message to the end user.

Sign Up Here

If you would like to test this example out, you can create a SignalWire account and space here.

Please feel free to reach out to us on our Community Slack or create a Support ticket if you need guidance!


Did this page help you?