Search for a virtual number using Node.js
Use this guide to setup your Node.js application for use with the Numbers API and search for an available Sinch virtual number.
Note:
Before you can get started, you need the following already set up:
- All Numbers API prerequisite steps.
- Node.js and a familiarity with how to create a new app.
Steps:
- Set up your Node.js application.
- Search for an available virtual number for SMS, Voice or both.
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
numbers-search
- 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
Search for an available virtual number
Create your file
Create a new file namedindex.js
in the project and paste the "Search for a virtual number" code.Fill in your parameters
Parameter | Your value |
---|---|
YOUR_ProjectID | The project ID found in the Sinch Customer Dashboard. |
YOUR_username | your client_id or key_id found in the Customer Dashboard. |
YOUR_password | Your client_secret or key_secret . This is generated upon new key creation. Generate a new key if you have lost your secret key. |
regionCode | The two letter abbreviation of the country for which you'd like a number. ISO 3166–1 alpha–2. |
type | The type of number you would like to rent. Available options are: MOBILE , LOCAL , or TOLL_FREE . Note that 10DLC numbers should be set to LOCAL . |
- Save the file.
Run the file
Run the following command in your terminal or command prompt:
node index.js
Response
The response should look something like this (repeated many times over!):
{
"availableNumbers": [
{
"phoneNumber": "+12089087284",
"regionCode": "US",
"type": "LOCAL",
"capability": ["SMS"],
"setupPrice": {
"currencyCode": "USD",
"amount": "0.00"
},
"monthlyPrice": {
"currencyCode": "USD",
"amount": "2.00"
},
"paymentIntervalMonths": 1
}
]
}
Next steps
Copy thephoneNumber
you would like to use and rent your virtual number using the Numbers API.Additional resources
- Explore the API specification to test more endpoints.
- Prefer a UI to search for a number? Follow the entire number searching and renting process in the Customer Dashboard.