# Rent the first available number using the Node.js SDK Use this guide to set up your Node.js application for use with the Numbers API and rent the first available Sinch virtual number and assign it to your SMS service plan. Note: Before you can get started, you need the following already set up: - - [NPM](https://www.npmjs.com/) and a familiarity with how to install packages. - [Node.js](https://nodejs.org/en/) and a familiarity with how to create a new app. Steps: 1. [Set up](#set-up-your-nodejs-application) your Node.js application 2. [Rent the first available virtual number](#rent-the-first-available-virtual-number) for SMS, Voice or both. ## Set up your Node.js application To quickly get started setting up a simple client application using the Node SDK: 1. If you haven't already, clone the [sinch-sdk-node-quickstart](https://github.com/sinch/sinch-sdk-node-quickstart) repository. 2. Navigate to the `templates/client` folder. 3. Open a command prompt or terminal and run the following command to install the necessary dependencies: ```shell npm install ``` 4. Open the `.env` [file](https://github.com/sinch/sinch-sdk-node-quickstart/blob/main/templates/client/.env). Using the [access key credentials](https://dashboard.sinch.com/settings/access-keys) from your Sinch Build Dashboard, populate the following fields with your values: | Field | Description | | --- | --- | | SINCH_PROJECT_ID | The unique ID of your Project. | | SINCH_KEY_ID | The unique ID of your access key. | | SINCH_KEY_SECRET | The secret that goes with your access key. **Note:** For security reasons, this secret is only visible right after access key creation. | If you're sending SMS messages, ensure you set your region in the `SMS_REGION` field. 5. Save the file. ### Modify your application 1. Navigate to the `/templates/client/src/numbers/` folder and open the `snippet.js` file. Replace the existing content within that file with the `snippet.js` code provided on this page. That code is also found [here](https://github.com/sinch/sinch-sdk-node-snippets/blob/main/snippets/numbers/available-numbers/rent-any/snippet.js) if you want to just replace the file. snippet.js //This code rents the first available number and configures it for use. // eslint-disable-next-line no-unused-vars import { Numbers, NumbersService } from '@sinch/sdk-core'; /** @param {NumbersService} numbersService */ export const execute = async (numbersService) => { const servicePlanId = 'YOUR_service_plan_id'; const appId = 'YOUR_app_id'; /** @type {Numbers.RentAnyNumberRequestSmsConfiguration} */ const smsConfiguration = { servicePlanId, }; /** @type {Numbers.RentAnyNumberRequestVoiceConfiguration} */ const voiceConfiguration = { appId, }; /** @type {Numbers.RentAnyNumberRequestData} */ const requestData = { rentAnyNumberRequestBody: { regionCode: 'US', type: 'LOCAL', numberPattern: { pattern: '+1781', searchPattern: 'START', }, smsConfiguration, voiceConfiguration, }, }; const response = await numbersService.availableNumber.rentAny(requestData); console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`); }; 1. The code provided in **snippet.js** includes default parameters. If you want, you can replace the following values for these parameters with your own values: | Parameter | Your value | | --- | --- | | `regionCode` | The two letter abbreviation of the country for which you'd like a number. For example, the United States is `US`. Should be in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-2) format. | | `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`. | | `servicePlanId` | Your [SMS service plan ID](https://dashboard.sinch.com/sms/api/rest). This is required for SMS configuration. | | `appId` | Your [Voice app ID](https://dashboard.sinch.com/voice/apps). This is required for Voice configuration. | 1. Save the file. ## Rent the first available virtual number Now you can run the code with the following command: ```Shell node src/app.js ``` This code will rent the first available number that fits the search criteria you specified and assign (or provision) it to your SMS service plan ID. ## Next steps Send a message to yourself using the SMS API or call yourself using the Voice API to verify that the configuration was successful. - [Send an SMS message](/docs/sms/getting-started). - [Make a phone call](/docs/voice/getting-started). ## Additional resources - Explore the [API specification](/docs/numbers/api-reference/numbers) to test more endpoints. - Prefer a UI to search for a number? Follow the entire number searching and renting process [in the Sinch Build Dashboard](https://dashboard.sinch.com/numbers/buy-numbers).