In this SMS API Quickstart, you'll learn how to send an SMS from your web application using the SMS API.
To start testing with the official NodeJS SDK for the SMS API, you need to first set up your test environment.
The following command will install MessageBird.
npm install messagebird
Now, let's create a send_sms.js file in the directory of your package.json file
Want to learn how to set up your NodeJS development environment? Check out the NodeJS tutorial
Next, enter your credentials and mobile number - as both the originator and recipient - to the snippet below and copy it to your send_sms.js file:
You can access and manage your credentials in the MessageBird Developer Dashboard.
Now, you can run the application by hitting run above or if you're running the example from your project, enter following command line:
node send_sms.js
Good job! You’ve sent your first SMS with the MessageBird SMS API!
Now, if you've run the example from your own project, let’s view MessageBird’s HTTP response to your API call.
If the set up was correct, you'll receive a response similar to this:
{id: '8144cda2abc84795a306c24b62f46a72',href: 'https://rest.messagebird.com/messages/8144cda2abc84795a306c24b62f46a72',direction: 'mt',type: 'sms',originator: '+31XXXXXXXXX',body: 'Hi! This is your first message',reference: null,validity: null,gateway: 10,typeDetails: {},datacoding: 'plain',mclass: 1,scheduledDatetime: null,createdDatetime: '2019-02-19T12:21:08+00:00',recipients:{ totalCount: 1,totalSentCount: 1,totalDeliveredCount: 0,totalDeliveryFailedCount: 0,items: [ [Object] ] }}
If something went wrong, you’ll receive an error response from the MessageBird API. Don't worry, simply head over to the SMS API Troubleshooting to understand the error.
Congrats! You can now programmatically send SMS with the MessageBird SMS API using NodeJS.