Allocate a virtual phone number

Rent a phone number from 46elks to be used for two-way sms or phone calls.

Request

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

Any number you allocate is a rental number. Get in touch if you need a portable number.

Request parameters

Parameter Example Description
country se A two-letter (ISO alpha 2) country code.
capabilities sms,voice A comma-separated string denoting the capabilities the number should have: sms, mms, voice, websocket, sip or webrtc. For example "sms", "sms,voice" or "websocket". Defaults to "sms,voice" if omitted.

Sample code

curl https://api.46elks.com/a1/numbers \
  -u <Username>:<API Password> \
  -d country=se \
  -d capabilities=sms,voice 
import HTTPotion.base
authdata = [basic_auth: {'',

request = %{
            "country"    => "se",
            "capabilities"      => "sms,voice"
           }

request_data = URI.encode_query(request)

HTTPotion.start
HTTPotion.post("https://api.46elks.com/a1/numbers",
  [body: request_data , ibrowse: authdata]
)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

public class UnirestSendcalls {
  public static void main(String[] args) {
    try {
      System.out.println("Sending calls");

      HttpResponse response = Unirest.post("https://api.46elks.com/a1/numbers")
        .basicAuth("","")
        .field("capabilities", "sms,voice")
        .field("country", "se")
        .asString();

      System.out.println(response.getBody());
      }

    catch (Exception e){
        System.out.println(e);
    }
  }
}
function allocatenumber ($calls) {
  $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($calls,'','&'),
      'timeout' => 10
  )));
  $response = file_get_contents("https://api.46elks.com/a1/numbers",
    false, $context);

  if (!strstr($http_response_header[0],"200 OK"))
    return $http_response_header[0];
  return $response;
}
$number = array(
  "country" => "se",
  "capabilities" => "sms,voice"  
);
echo allocatenumber($number);
import requests

auth = (
    '',
    ''
    )

fields = {
    'country': 'se',
    'capabilities': 'sms,voice'
    }

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

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

uri = URI('https://api.46elks.com/a1/numbers')
req = Net::HTTP::Post.new(uri)
req.basic_auth '', ''
req.set_form_data(
  :country => 'se',
  :capabilities => 'sms,voice'
)

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
sms_url http://yourapp.example/new_sms
{forward":"+46700000000"}
URL / JSON handling incoming SMS.
voice_start http://yourapp.example/new_call
{"connect":"+46700000000"}
URL / JSON handling incoming calls.
mms_url http://yourapp.example/new_mms URL handling incoming MMS.
websocket_url wss://yourapp.example/elks/calls Websocket URL the API connects to when the number receives a call. Must start with ws:// or wss://, and requires the websocket capability. See Realtime Voice.
category mobile/fixed Mobile or landline numbers. Landline numbers can't have SMS capabilities. WebSocket, SIP and WebRTC numbers use the categories websocket, sip and webrtc respectively.

Number types

Type of number Capabilities Parameters
Virtual phone number One or more of sms, voice, mms sms_url, mms_url, voice_start, sms_replies
SIP number voice, sip Incoming calls are delivered to your SIP client
WebSocket number websocket websocket_url
WebRTC number voice, webrtc voice_start

The name parameter can be set on any number.

Response

Example JSON response
{
  "id": "n57c8f48af76bf986a14f251b35389e8b",
  "active": "yes",
  "country": "se",
  "number": "+46766861001",
  "capabilities": [ "sms", "voice", "mms" ],
}
Parameter Type Description
id string ID of the allocated number.
active string If the number is active or not, always "yes" on newly allocated numbers.
country string A two-letter (ISO alpha 2) country code.
number string The phone number in E.164 format.
capabilities list The capabilities of the number, for example [ "sms", "voice" ] or [ "websocket" ].

Additional information

Any number you allocate is a rental number. Get in touch if you need a portable number.