Send text messages to mobile phones.
POST https://api.46elks.com/a1/sms
Parameter | Example | Description |
---|---|---|
from |
YourCompany +46766861004 |
The sender of the SMS as seen by the recipient. Either a text sender ID or a phone number in E.164 format if you want to be able to receive replies. |
to | +46766861004 | The phone number of the recipient in E.164 format. |
message | Hello there! | The message to send. |
curl https://api.46elks.com/a1/sms \
-u <api_username>:<api_password> \
-d from=CurlyElk \
-d to=+46766861004 \
-d message="Bring a sweater, it's cold outside"
import HTTPotion.base
authdata = [basic_auth: {'<API-Username>',
'<API-Password>'}]
request = %{
"from" => "ElixirElk",
"to" => "+46766861004",
"message" => "Bring a sweater, it’s cold outside!"
}
request_data = URI.encode_query(request)
HTTPotion.start
HTTPotion.post("https://api.46elks.com/a1/sms",
[body: request_data , ibrowse: authdata]
)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
public class UnirestSendSMS {
public static void main(String[] args) {
try {
System.out.println("Sending SMS");
HttpResponse response = Unirest.post("https://api.46elks.com/a1/sms")
.basicAuth("<API Username>","<API Password>")
.field("to", "+46766861004")
.field("from", "JavaElk")
.field("message", "Bring a sweater, it’s cold outside!")
.asString();
System.out.println(response.getBody());
}
catch (Exception e){
System.out.println(e);
}
}
}
import HTTPotion.base
const https = require('https')
const querystring = require('querystring')
const username = 'API-username'
const password = 'API-password'
const postFields = {
from: "NodeElk",
to: "+46766861004",
message: "Bring a sweater it's cold outside!"
}
const key = new Buffer(username + ':' + password).toString('base64')
const postData = querystring.stringify(postFields)
const options = {
hostname: 'api.46elks.com',
path: '/a1/SMS',
method: 'POST',
headers: {
'Authorization': 'Basic ' + key
}
}
const callback = (response) => {
var str = ''
response.on('data', (chunk) => {
str += chunk
})
response.on('end', () => {
console.log(str)
})
}
var request = https.request(options, callback)
request.write(postData)
request.end()
function sendSMS ($sms) {
$username = "USERNAME";
$password = "PASSWORD";
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Authorization: Basic '.
base64_encode($username.':'.$password). "\r\n".
"Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query($sms),
'timeout' => 10
)));
$response = file_get_contents("https://api.46elks.com/a1/sms",
false, $context);
if (!strstr($http_response_header[0],"200 OK"))
return $http_response_header[0];
return $response;
}
$sms = array(
"from" => "PHPElk", /* Can be up to 11 alphanumeric characters */
"to" => "+46766861004", /* The mobile number you want to send to */
"message" => "Bring a sweater, it's cold outside!",
);
echo sendSMS($sms);
import requests
requests.post(
'https://api.46elks.com/a1/sms',
auth = (API_USERNAME, API_PASSWORD),
data = {
'from': 'PythonElk',
'to': '+46766861004',
'message': "It's cold outside, bring a sweater!"
}
)
require 'net/http'
uri = URI('https://api.46elks.com/a1/sms')
req = Net::HTTP::Post.new(uri)
req.basic_auth '<API Username>', '<API Password>'
req.set_form_data(
:from => 'RubyElk',
:to => '+46704508449',
:message => 'Login code 123456'
)
res = Net::HTTP.start(
uri.host,
uri.port,
:use_ssl => uri.scheme == 'https') do |http|
http.request req
end
puts res.body
Parameter | Example | Description |
---|---|---|
dryrun | yes |
Enable when you want to verify your API request without actually sending an SMS to a mobile phone. No SMS message will be sent when this is enabled. |
whendelivered | http://hello.io/ping | This webhook URL will receive a POST request every time the delivery status changes. |
flashsms | yes | Send the message as a Flash SMS. The message will be displayed immediately upon arrival and not stored. |
dontlog | message |
Enable to avoid storing the message text in your history. The other parameters will still be stored. |
{
"id": "s70df59406a1b4643b96f3f91e0bfb7b0",
"from": "YourCompany",
"to": "+46766861004",
"message": "This is the message sent to the phone.",
"created": "2018-07-11T13:37:42.314100",
"cost": 3500,
"direction": "outgoing"
}
Attribute | Type | Description |
---|---|---|
status | string |
Current delivery status of the message. Possible values are "created", "sent", "failed" and "delivered". |
id | string | Unique identifier for this SMS. |
from | string |
The sender of the SMS as seen by the recipient. String may start with a letter and contain numbers - Max 11 characters including A-Z, a-z, 0-9. |
to | string | The phone number of the recipient in E.164 format. |
message | string | The message text. |
created | string | Time in UTC when the SMS was created. |
delivered | string | Time in UTC if the SMS has been successfully delivered. |
cost | integer | Cost of sending the SMS. Specified in 10000s of the currency of your account. For an account with currency SEK a cost of 3500 means that the price for sending this SMS was 0.35 SEK. |
direction | string | The direction of the SMS. Set to "outgoing" for sent SMS. |
dontlog | string | Set to "message" if dontlog was enabled. |
estimated_cost | integer | Replaces cost in the response if dryrun was enabled. |
parts | integer | Number of parts the SMS was divided into. |
Default maximum throughput is 100 SMS per minute per account.
Additional messages will be queued and sent in-order.
Contact support if you require additional throughput.
SMS messages should always be sent to the API as URL-encoded UTF-8. The maximum text size of a single message is 160 characters. If your message contains characters not available in the GSM 03.38 basic character set it will be encoded as UTF16-BE which as a general rule means up to 70 characters in a single SMS message. You can use \n in a message if you want to get a new line.
Longer and more expensive SMS messages can be sent. For messages within GSM 03.38 basic, the calculation is N * 153 where N is the number of SMS parts required. For UTF16-BE, the calculation is N * 67 - however, less for code points above 65535.
Splitting and joining multi-part SMS messages are automatically handled by the API. When your message is being split, your account will be charged for each SMS part.
Created:We've received your request.
Sent:We've sent your message to the recipient
Failed:Unable to deliver your message
Delivered:Message has reached recipient's phone.