The following example shows how you can send and receive messages using our REST API.
AngularJS provides a built-in service that facilitates communication with the remote HTTP servers via the browser’s XMLHttpRequest object or via JSONP. All you need to do is inject it in your service or controller.
Send SMS Message
angular.module('myApp', []).controller('myCtrl', function ($scope, $http) { var req = { user: "user@email.goes.here", // Replace with your user pass: "user_password_goes_here", // Replace with your password source: "virtual_number", // Replace with your sender ID destination: "recipient_mobile", // Replace with the recipient number sms: "Test Message 1", // Replace with your message }; $http.get("http://api.123-txt.com/Api123WCF.svc/rest/SendSms", {params: req}); });
Send SMS Message Advanced
angular.module('myApp', []).controller('myCtrl', function ($scope, $http) { var req = { user: "user@email.goes.here", // Replace with your user pass: "user_password_goes_here", // Replace with your password source: "virtual_number", // Replace with your sender ID destinations: [ // Replace with the recipient number(s) array "dest_number_1", "dest_number_2", ], sms: "Test Message 1" // Replace with your message } $http.post("http://api.123-txt.com/Api123WCF.svc/rest/SendSmsAdvanced", req).success(function(res) { if(res) { $scope.sendResponseAdv = res; } }); });
Receive Messages
angular.module('myApp', []).controller('myCtrl', function ($scope, $http) { var req = { user: "user@email.goes.here", // Replace with your user pass: "user_password_goes_here", // Replace with your password maxRecords: "20", // Limit number of records returned, max 100 per call. lastDate: "2015-01-28 10:30:46" // Limit to messages newer than this date } $http.get("http://api.123-txt.com/Api123WCF.svc/rest/ReceiveSms", {params: req}).success(function(res) { if(res.SmsList.length > 0) { $scope.messages = res.SmsList; } }); });
Note: The response from this method will contain a date which you can then use to set to ‘lastDate’ in your next call, this will ensure you do not pull duplicate incoming messages from the service.
Get Message Statuses
angular.module('myApp', []).controller('myCtrl', function ($scope, $http) { var req = { user: "user@email.goes.here", // Replace with your user pass: "user_password_goes_here", // Replace with your password destIds: [ // Replace with destination IDs array "1b07cd75-0376-444a-a7f0-1a7ea479faaf", "791e291c-8436-49b3-8a39-5f6333cb1322", ], } $http.post("http://api.123-txt.com/Api123WCF.svc/rest/SentSmsStatus", req).success(function(res) { if(res) { $scope.messageStatuses = res; } }); });
Note: SendSmsAdvanced returns the destId’s of each sent message, you must hold onto these IDs and use them within SentSmsStatus to identify their current and final delivery states.