Send a fax to Dropbox
Time to read: 3 minutes
Dropbox has a wonderful API that allows you pass a publicly available URL and it will download the data and store it into dropbox on your behalf. This is incredibly useful since Twilio on receipt of fax builds a URL which the content can be accessed from.
We don't even have to download the attachment and stream it to Dropbox, Dropbox will do it for us!
Prerequisites to Fax with Dropbox
- A fax enabled number from Twilio
- A Dropbox account
Dropbox Setup
Login to your dropbox account (or create a new one here) and navigate to https://www.dropbox.com/developers/apps/create.
Create a Dropbox app
Next, you'll need to create a new DropBox app.
- Select Dropbox API
- Select App folder
- Give your folder a name like Modern Fax
Configure your Dropbox App
In the following screen, in the OAuth2 section:
- Set Allow implicit grant = Disallow
- Click Generate access token and save this for later
Create a function to receive faxes
We need to tell Twilio what we should do when we want to receive a fax. In our case, we want to push the file to Dropbox.
Setup Config
- Add a new environment variable called DBX_ACCESS_TOKEN and paste in your access token.
- Add a new dependency for the npm package request version 2.88.0
Create a Function
- Create a new function
- Set the Function Name = Modern Fax
- Set the Path = /fax-to-dropbox
- Copy/Paste the code below into your function
- Click Copy on the function url, and paste somewhere. You'll need it in the next step!
Create a TwiML Bin
Now we need to tell Twilio if we want to receive the incoming fax or not. We have two options, <Receive> or <Reject>. In this example, we won't build any special logic to reject faxes, we will just take everything.
- Navigate to https://www.twilio.com/console/runtime/twiml-bins
- Create a New TwiML Bin
- Set Friendly Name = Fax Handler
- Set TwiML = the code below.
- Replace {function_url} with the full URL to the function you created above.
Configure your Twilio Number
You're going to need a Twilio number that supports fax to build this app, so log in to your Twilio account. You can buy a new number or you may already have one, just look for this icon to show that it can receive fax:
Once you have your number, you'll need to configure it to point to the TwiML Bin you created. Head back to edit your fax capable number. In the "Voice & Fax" section make sure you are set to accept incoming faxes.
For "A fax comes in" select TwiML and then select the TwiML Bin Modern Fax.
Testing out Dropbox faxes
As we already established, it's 2019 and we don't have a fax machine to test this with. Now, you can either head down to your local library or print shop and ask to borrow theirs, or pop open the Twilio API explorer and send yourself a fax via the API (you can use your existing fax number as both the To
and From
number here). When sending a fax you need to have a PDF hosted somewhere that Twilio can reach it. If you don't have one, feel free to use our test PDF file here.
Don't forget to play the authentic sounds of a fax machine as you send it off into the world.
Wait a couple of minutes (faxes take time!) and then check your Dropbox folder.
We got a fax!
And there you have it, a Twilio-linked DropBox fax receiving app in just a few minutes.
We hope this demonstration inspires your next fax-app – or fax-related hack, anyway. We can't wait to see what you build!
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.