Sending SMS via Vonage APIs
Revision as of 16:37, 25 May 2020 by Pavel.lobko (talk | contribs)
Such a common task as SMS confirmation or any type of Viber/Whatsapp messages can be solved pretty easy with the help of numerous web services. Now we will show you how to send SMS from the green screen with the only command using i2Rest Client. Two things we have to take care before start messaging:
- registration on Nexmo.com
- adding Nexmo.com SSL certificate CA to your DCM - see "how to" instructions
When the preparations are completed, all we have to do - is just compose our POST request following the instructions. And here is our i2Rest Client command:
I2REST COMMAND(*POST) URL('https://rest.nexmo.com/sms/json') BODY(*N 'api_key=<your_api_key>&api_secret=<your_api_secret> &from=Vonage%20SMS%20API&text=Hello%20from%20i2R est&to=<Your_phone_number>' 'application/x-www-form-url encoded') OUTPUT(*BOTH) DCMCLIENT(<your_DCM_client>) RECVLOG('/home/logs/SMS.log') SENTLOG('/home/logs/SMS.log') AUTHMETHOD(*NONE)
The same result can be also achieved with application/json
request body. The command should look like this:
I2REST COMMAND(*POST) URL('https://rest.nexmo.com/sms/json') BODY(*N '{"api_key":"<your_api_key", "api_secret":"<your_api_secret>", "from":"Vonage SMS API", "to":"<your_phone_number>", "text":"Hello from i2Rest"}' 'application/json') OUTPUT(*BOTH) DCMCLIENT(<your_DCM_client>) RECVLOG('/home/logs/SMS.log') SENTLOG('/home/logs/SMS.log') AUTHMETHOD(*NONE)
Let's see server response in SMS.log.
Server response (status 200, shown 259 bytes of 259): { "message-count": "1", "messages": [{ "to": "123456789100", "message-id": "13000000E084F19C", "status": "0", "remaining-balance": "1.27900000", "message-price": "0.10300000", "network": "25702" }] }