Send SMS with Dotdigital's Omnichannel API using C#

This tutorial will show you how to send SMS using Dotdigital's Omnichannel API and C#. Click the "Start" button below to start the tutorial.

Start Tutorial

Sending SMS using Dotdigital Omnichannel API and C#

This short tutorial will show you how to send SMS using the Dotdigital Omnichannel API; it's quick and easy!

The tutorial's navigation controls are located above this text. Use to move to the next step of the tutorial. Use to move to the previous step of the tutorial (if there is one). Use to see an overview of all the steps in the tutorial.

To begin with you will need the following prerequisites installed:

  • Visual Studio 2017 or higher

Enter your details

To get the tutorial code to run successfully you need to enter your Dotdigital API user credentials and a target mobile number.

To create an API User please see this tutorial

Enter you mobile number

Enter your mobile number in international format, which is:

  • Your country code i.e. 44 for the UK
  • Your mobile number with any leading zeros removed e.g. if your local number is 07123 123 123 you would use 71234123123
  • Remove any non numeric characters

e.g. If you lived in the UK and had a mobile number of 07123 123123 then in international format it would be 447123123123

Running the code

You are now ready to run the code and send an SMS, but please ensure you have Pay As You Go billing enabled on your account first; talk to your account manager if you need this enabling please.

To run simply press play within Visual Studio and a console will open.

When prompted type single to send a single SMS message.

You should receive your SMS shortly, if a successful response was returned.

Understanding the code

The Dotdigital Omnichannel API is very easy to use, we'll just explain what the code is this tutorial does.

RESTful APIs

The Dotdigital Omnichannel API is RESTful and therefore utilizes the abilities of the HTTP protocol in order to derive action and context.

In the tutorial the URL we POST to contains the action or entity we are interested in and the HTTP verb POST indicates we want to send a message.

Authentication is very easy as it uses the HTTP protocols basic auth, with a set of API User credentials.

The Request object

The request object is used to describe the message you want to send and via what channels. As a minimum it is composed of:

body

The body is the text message body you want to send. The Omnichannel API will automatically ensure this message can be sent on any supported channels.

to

The to object should be populated with any addressing information that might be used by the channels you want to send on, such as:

  • phoneNumber
  • email
  • fbMessengerId
  • etc...

No from?

You don't need to define who the SMS is from by default as this will simply tell dotdigital you want it to select an appropriate from for the destination country using its Localizer and Stitching feature.

See our full documentation for more details.

The Request object with channel options

The request object can optionally have additional channelOptions defined to allow you finer control over the SMS send, options are:

from

The from is the phone number, alpha identifier, or short code you are sending from.

allowUnicode

The allowUnicode options toggles whether having Unicode characters in the message body will be allowed or not.

See our full documentation for more details.

Using a serializable object

In the example we have used a serializable object to create the request JSON for the REST call. You can simply create a JSON string and pass this, but a serializable object gives you type safety and easier to understand code.

We serialize the object to JSON using the popular library JSON.Net which is included using NuGet.

Making the web service call

We have used the popular REST library RESTSharp to make the code simpler when calling REST web services in C#.

In the highlighted code you can see how we build the request object using serialization to create the request bodies JSON and then POST it to the web service.

Batch Sending

The API also supports the sending of messages in a batch which should be used when their is more than one recipient as it will be much more efficient than calling the single send method multiple times.

The web method is very simple as it accepts an array of message requests as used in the single submission method described in this tutorial. The web method on being successfully called returns an array of messageId, one for each submitted message request.

To run simply press play within Visual Studio and a console will open.

When prompted type batch to send a batch of SMS messages.

You should receive your SMSs shortly, if a successful response was returned with your message ids for each message in the request array.

See our full documentation for more details.

All done

Thanks for taking the time to look through the tutorial, to find out more visit our full documentation.