1. Create a user

To be able to receive and respond to SMS with the 46elks API you will need a 46elks phone number. The easiest way to get such a number is to login to the dashboard, go to the Numbers page and add a number with SMS enabled to your 46elks account. This is your number that you can use to send and receive text messages.

2. Username and password

Once you have an account you will be automatically logged in to the 46elks dashboard. This is where you can see all your important account information - like the username and password you need to send an SMS.

Tip: Click "View" beside the blurred text under API Credentials to see your own password.

Every time you do something with 46elks, like sending an SMS, you have to provide your API-username and API-password via Basic HTTP Authentication.

3. Send an SMS

Finally, it’s time to write some C# code. Your code needs to be able to do the following:

using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace elktest {
  class Program {
    public static string user = "<YOUR USERNAME>"; // Specify your API username
    public static string pwd = "<YOUR PASSWORD>"; // Specify your API password
    private static HttpClient client;
    static void Main(string[] args)
      client = new HttpClient();
      client.BaseAddress = new Uri("https://api.46elks.com");

      client.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue(
              string.Format("{0}:{1}", user, pwd)

      var content = new FormUrlEncodedContent(new[] {

        // The sender of the SMS, 3 to 11 characters
        new KeyValuePair < string, string > ("from", "ElkCo"),

        // The number that will receive the text message
        new KeyValuePair < string, string > ("to", "<YOUR PHONENUMBER>"),

        // The content of the text message
        new KeyValuePair < string, string > (
          "message","It's cold outside, bring a sweater!"),

      HttpResponseMessage response = client
        .PostAsync("/a1/SMS", content).Result;

      // If 200 OK then SMS is sent and it is possible to handle response.
      if(response.StatusCode == HttpStatusCode.OK){
        string result = response.Content.ReadAsStringAsync().Result;

        // Decode the data from the API:
        SMS sms = JsonConvert.DeserializeObject<SMS>(result);
      // Else there is an error and the response will be a string with an error description.
        string result = "Error: " + response.Content.ReadAsStringAsync().Result;
        Console.WriteLine(result); // Typicaly throw an error here.
  // Class for response object from the 46elks SMS API.
  public class SMS {
    public string id { get; set; }
    public string from { get; set; }
    public string to { get; set; }
    public string message { get; set; }
    public string status { get; set; }
    public string created { get; set; }
    public string direction { get; set; }
    public int parts { get; set; }
    public string owner { get; set; }
    public int cost { get; set; }

Project file

<Project Sdk="Microsoft.NET.Sdk">
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />

The example is tested in .NET Core 1.1.0

Tip: The phone number to send to should be formatted with country code and without spaces, dashes or parentheses. For example +468123123 and not 08-123123 or +46 (8) 123 123.

If you are new to .NET Core, here are some additional pointers for you:

  1. Download and Install .NET Core.
  2. Open your terminal and run the following commands:
dotnet new console -o send_sms_with_46elks_and_csharp
cd send_sms_with_46elks_and_csharp
vim Program.cs # Use your favorite code editor to replace the content of the file with the example code.
dotnet add package Newtonsoft.Json
dotnet restore
dotnet run

Next step

You’ve just sent a text message with a text sender (i.e. not from a phone number). By doing this you can use SMS to remind customers of reservations, send confirmations of new orders, etc.

To send an SMS is the easiest way to get started with 46elks, but you can do so much more. For example you can receive SMS, automatically respond to an incoming SMS or handle voice calls. For this and more there are a load of C# examples at GitHub.

If you have any questions then get in touch, we love talking to our users!