Send an SMS

Send text messages to mobile phones.

Request

POST https://api.46elks.com/a1/sms

Request parameters

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.

Sample code

curl https://api.46elks.com/a1/SMS \
  -u <Username>:<API Password> \
  -d from=CurlyElk \
  -d to=+46766861004 \
  -d message="Bring a sweater, it's cold outside"
import HTTPotion.base
authdata = [basic_auth: {'',

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("","")
        .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);
    }
  }
}
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

auth = (
    '',
    ''
    )

fields = {
    'from': 'PythonElk',
    'to': '+46723175800',
    'message': 'Test Message To your phone.'
    }

response = requests.post(
    "https://api.46elks.com/a1/SMS",
    data=fields,
    auth=auth
    )

print(response.text)
require 'net/http'

uri = URI('https://api.46elks.com/a1/SMS')
req = Net::HTTP::Post.new(uri)
req.basic_auth '', ''
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

More examples
C - C# - Go - Google App Script - Haskell - Node.js - Postman

Optional request parameters

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.

Response

Example JSON response
{
  "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.
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.

Additional info

Throughput

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.

Message texts and costs

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.