Make a call with Node.js
You can quickly see how the Voice API works by calling yourself using the API.
In this guide you will learn how to:
In this guide you will learn:
What you need to know before you start
Before you can get started, you need the following already set up:
- Set all Fax API configuration settings.
- Node.js and a familiarity with how to create a new app.
Set up your Node.js application
First we'll create a Node project using npm. This creates a package.json and the core dependencies necessary to start coding.
To create the project, do the following steps:
- Create a folder called
fax-send
- Navigate into the folder you created and run the following command.
npm init
This command adds the node_modules folder and the package.json file. You will be prompted to provide values for the fields. For this tutorial, you can simply accept the default values and press enter at each stage.
- Add the axios package with npm to generate the necessary dependencies.
npm install 'axios'
Create your file
Create a new file named index.js in the project and paste the provided "Index.js" code into the file.
Note:
This tutorial uses basic authentication for testing purposes. We recommend using OAuth token-based authentiation for production.
This code sends a fax to a specified number using the Sinch Fax API.
To
In this example you want to fax a phone number which is configured to receive faxes. Change the value of theto
parameter to the Sinch phone number you purchased and configured for Fax in your dashboard in E.164 format.Content URL
The Fax API can send either files directly or the URL of a web page or other online resource. For the purposes of this tutorial, we have provided a PDF file you can use to test, or feel free to use a web page of your choosing. Change the value ofYOUR_content_url
to one of the following URLs:https://developers.sinch.com/fax/fax.pdf
- The URL of the web page you want to send.
Note:
You can use any URL on the Internet (including ones with basic authentication), and we'll pull it down and make it a fax. This might be useful to you if you're using a web framework for templates and creating fax files.
If you are passing fax a secure URL (starting withhttps://
), make sure that your SSL certificate (including your intermediate cert, if you have one) is installed properly, valid, and up-to-date.Callback URL
If you provide a callback URL on your Fax service, the Fax API can send notification events to your server about your outgoing fax, such as when or if the fax was delivered. You can set that callback URL in your request body. Change the value ofYOUR_callback_url
to the URL of your server that's listening to incoming requests.Fill in your parameters
Before you can run the code, you need to update some more values in theIndex.js
file so you can connect to your Sinch account. Update the following parameters with your own values:Parameter | Your value |
---|---|
YOUR_project_id | The project ID found on your Sinch dashboard. |
YOUR_access_key | The access key found on your Sinch dashboard. |
YOUR_access_secret | The access secret found on your Sinch dashboard. Note: Access secrets are only available during initial key creation. |
Save the file.
Send your first fax
Now you can execute the code and send your fax. Run the following command:
node index.js
You should receive a fax to the number you specified with the web page that you configured.
Troubleshooting tip
If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.
Next steps
Now that you know how to send a fax, now it's time to learn how to receive a fax sent to your Sinch number.