After searching for a number, rent and configure that number for SMS, Voice or both.
Before you can get started, you need the following already set up:
All Numbers API prerequisite steps.
- NPM and a familiarity with how to install packages.
- Node.js and a familiarity with how to create a new app.
- A virtual number you have confirmed to be available.
- Set up your Node.js application
- Rent and configure your number for SMS.
To quickly get started setting up a simple client application using the Node SDK:
If you haven't already, clone the sinch-sdk-node-quickstart repository.
Navigate to the
templates/client
folder.Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm install
Open the
.env
file. Using the access key credentials 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.NoteIf you're sending SMS messages, ensure you set your region in the
SMS_REGION
field.Save the file.
- Navigate to the
/templates/client/src/numbers/
folder and open thesnippet.js
file. Replace the existing content within that file with thesnippet.js
code provided on this page. That code is also found here if you want to just replace the file.
//This code rents and configures a specific virtual number.
// eslint-disable-next-line no-unused-vars
import { Numbers, NumbersService } from '@sinch/sdk-core';
/** @param {NumbersService} numbersService */
export const execute = async (numbersService) => {
// Available numbers list can be retrieved by using list() function from available service, see:
// https://developers.sinch.com/docs/numbers/getting-started/node-sdk/searchavailable/
const phoneNumber = 'available_phone_number_to_be_rented';
const servicePlanId = 'YOUR_service_plan_id';
/** @type {Numbers.RentNumberRequestData} */
const requestData = {
phoneNumber,
rentNumberRequestBody: {
smsConfiguration: {
servicePlanId,
},
},
};
const response = await numbersService.availableNumber.rent(requestData);
console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`);
};
- 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 |
---|---|
servicePlanId | Your SMS service plan ID. This is only required for SMS configuration. |
phoneNumber | The virtual phone number that you previously searched for and would like to rent. |
- Save the file.
Now you can execute the code. Run the following command:
node src/app.js
You should get a response similar to this one:
{
"phoneNumber": "+12025550134",
"projectId": "51bc3f40-f266-4ca8-8938-a1ed0ff32b9a",
"displayName": "string",
"regionCode": "US",
"type": "MOBILE",
"capability": [
"SMS"
],
"money": {
"currencyCode": "USD",
"amount": "2.00"
},
"paymentIntervalMonths": 0,
"nextChargeDate": "2019-08-24T14:15:22Z",
"expireAt": "2019-08-24T14:15:22Z",
"smsConfiguration": {
"servicePlanId": "82b42acf74924bd687ef9fb212f2060c",
"scheduledProvisioning": {
"servicePlanId": "82b42acf74924bd687ef9fb212f20611",
"status": "WAITING",
"lastUpdatedTime": "2019-08-24T14:15:22Z",
"campaignId": "string",
"errorCodes": [
"INTERNAL_ERROR"
]
},
"campaignId": "string"
},
"voiceConfiguration": {
"appId": "string",
"scheduledVoiceProvisioning": {
"appId": "string",
"status": "WAITING",
"lastUpdatedTime": "2019-08-24T14:15:22Z"
},
"lastUpdatedTime": "2019-08-24T14:15:22Z"
}
}
Send a message to yourself using the SMS API to verify that the configuration was successful.
- Explore the API specification to test more endpoints.
- Follow the number rental process in the Sinch Build Dashboard UI rather than through this API.