Send an SMS Message with Node.js
Note:
Before you can get started, you need the following already set up:
- Set all SMS API configuration settings.
- Node.js and a familiarity with how to create a new app.
Quickly send SMS messages in a Node.js application with the Sinch SMS API.
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
send-sms-app - Navigate into the folder you created and run the following command.
npm initThis command adds 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 namedindex.js in the project and paste the provided "Send an SMS message" code into the file.Fill in your parameters
- Assign your values to the following parameters:
Parameter Your value SERVICE_PLAN_IDThe service plan ID found on your Sinch Customer Dashboard. SMS > APIs > REST configuration API_TOKENThe API token found on your Sinch Customer dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token. SINCH_NUMBERAny number you've assigned to your Sinch account. Find the number on your Sinch Customer Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. TO_NUMBERThe phone number to which you want to send the test SMS message. REGIONDouble check that the region is correct on your base URL. Learn more about regional options here. - Then, save the file.
Send your first SMS message
Now you can execute the code and send your test SMS message.
Run the following command:
node index.jsNext steps
The code used in the index.js file sends a POST request to the Sinch SMS API/batches endpoint to send the SMS message. Read more about the batches endpoint.Additional resources
- Visit our API specification to test more endpoints.