Sending SMS with our API
This guide shows how to send a message using our REST API.
Send SMS code
var messagingService = new MessagingService("username", "api-password");
messagingService.SendMessage(new SmsMessage("07123456789", "Hello!", "accountRef"));
$message = new \Esendex\Model\DispatchMessage(
"WebApp", // Send from
"01234567890", // Send to any valid number
"My Web App is SMS enabled!",
\Esendex\Model\Message::SmsType
);
$authentication = new \Esendex\Authentication\LoginAuthentication(
"EX000000", // Your Esendex Account Reference
"user@example.com", // Your login email address
"api-password" // Your API password
);
$service = new \Esendex\DispatchService($authentication);
$result = $service->send($message);
print $result->id();
print $result->uri();
UserPassword userPassword = new UserPassword("YourUsername","YourApiPassword");
BasicServiceFactory serviceFactory = ServiceFactory.createBasicAuthenticatingFactory(userPassword);
MessagingService messagingService = serviceFactory.getMessagingService();
SmsMessageRequest message = new SmsMessageRequest("RecipientNumber", "YourMessage");
MessageResultResponse response;
try{
response = messagingService.sendMessage("YourAccountReference", message);
}catch(Exception e){
e.getStackTrace();
}
#Insert the following code in a file (eg. esendex.rb) in the configs/initializers.
Esendex.configure do |config|
config.username = "<username>"
config.password = "<api-password>"
config.account_reference = "<account_reference>"
end
#Insert the following code in a function.
account = Account.new
batch_id = account.send_message( to: "RecipientNumber", body: "YourMessage")
var config = require('./config'),
esendex = require('../')(config);
var messages = {
accountreference: config.accountreference,
message: [{
to: "07896563254",
body: "Every message matters!"
}]
};
esendex.messages.send(messages, function (err, response) {
if (err) return console.log('error: ', err);
console.dir(response);
});
accountClient := New("user@example.com", "api-password").Account("EX00000")
accountClient.Send([]Message{
{To: "00000000", Body: "Hello"},
})
These examples require the SDKs
You will need
- Your Esendex account reference (EX0xxxxxx), username and API password.
- Don't have an account yet? You'll need to create an account.
- Need an API password? You can generate one on your user profile.
Handling the response
We will send you back an XML
acknowledgment with a HTTP Status Code
of 200 if successful. The response will include the batch ID
of the submission and an ID
for the message.
What you might want to do with the response
You may wish to store the batch ID
in your system against the action that triggered your system to generate the request to send a message. You may also wish to store the individual message ID
. By storing the message ID
you can retrieve the status of the batch or message from the REST API in the future.
What else you might want to do when sending a message
- Set a name that the
SMS
message will appear to be from (e.g. "12345" or "MyCompany") - Schedule a message to be sent later
- Send a voice message
What you might want to do next
What are the next steps in your process?
- Are you expecting a response back from the message? If so you might want learn how to receive a message via the REST API
- Do you need to know when a message is delivered or if it fails? If so you might want to check the status of a message.
- Are you making frequent calls to the REST API? Would you prefer to use session authentication instead of using basic authentication with each request?
A note on API access
In order to allow customers to manage what their users can do on their account, access to the API is restricted to users with Admin and Standard roles on an account (in most cases this shouldn't be an issue as Admin is the default role of new users).
To manage the roles of users on an account, once you've signed up:
- Log in to Echo
- Go to Settings -> User Management