Assign a number to your SIP trunk with Node.js
You can manage your Elastic SIP trunks with the API and assign a phone number to your SIP trunk.
In this guide you will learn:
- How to set up your your Node.js app
- How to assign a phone number
What you need to know before you start
Before you can get started, you need the following already set up:
- Set all Elastic SIP Trunking API configuration settings.
- NPM and a familiarity with how to install packages.
- Node.js and a familiarity with how to create a new app.
- A created SIP trunk.
Set up your Node.js application
Create and then navigate to a new folder where you want to store your project. Create a new node app with npm.
npm init
Accept the defaults for the application.
Install your dependencies
We will be using the axios package to make HTTP requests.
Use the following command to install the axios package:
npm install axios
Create your file
In your project folder, create a new file named index.js in the project and paste the provided "index.js" code into the file.
This code makes a POST request to the EST API /trunks/{SIP_TRUNK_ID}/phoneNumbers endpoint which assigns the phone number you specified in thePHONE_NUMBER
variable.Fill in your parameters
Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values:
Parameter | Your value |
---|---|
PROJECT_ID | The project ID to which your SIP trunk belongs. You can find this on your Sinch dashboard. |
SIP_TRUNK_ID | The ID of the SIP trunk to which you want to assign the number. |
USERNAME | The application key found on your Sinch dashboard. |
PASSWORD | The application secret found on your Sinch dashboard. |
PHONE_NUMBER | This should be a number you own or have access to. |
Save the file.
Assign your phone number
Now you can execute the code and assign your phone number. Run the following command:
node index.js
In your console, you should see a success response showing that the phone number was added to the SIP trunk.