Before you start
- You need a ClickSend account with credit to start sending. If you don’t have an account, create one here.
- If you need to add more credit to your account, you can top up here. You’ll be credited $2 AUD free credit when you sign up.
Installation
Dependencies
- RestSharp - Version 106.11.7 or later
- Json.NET - Version 12.0.3 or later
- JsonSubTypes - Version 1.8.0 or later
The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:
Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.Configuration.ConfigurationManager
Run the following command to generate the DLL, and include it (under the bin
folder) in the C# project.
/bin/sh build.sh
Send your first message
Below is the full snippet you can use to send an SMS. It includes placeholders that will need to be replaced when implementing the code in your project.
Placeholder | Replace with |
---|---|
| Your ClickSend Username. Find it here. |
| Your ClickSend API Key. Find it here. |
| The origin identifier for your API request, which could be the name of your application or the source location for the request. |
| The content of your SMS message. |
| The phone number you're sending the message to, including the country code. |
using IO.ClickSend.ClickSend.Api;
using IO.ClickSend.Client;
using IO.ClickSend.ClickSend.Model;
var configuration = new Configuration()
{
Username = USERNAME,
Password = API_KEY
};
var smsApi = new SMSApi(configuration);
var listOfSms = new List<SmsMessage>
{
new SmsMessage(
source: "SOURCE",
body: "MESSAGE",
to: "TO_PHONE_NUMBER"
)
};
var smsCollection = new SmsMessageCollection(listOfSms);
var response = smsApi.SmsSendPost(smsCollection);
The code explained
Import namespaces
Prepare your environment to use the ClickSend API by importing the required namespaces.
using IO.ClickSend.ClickSend.Api;
using IO.ClickSend.Client;
using IO.ClickSend.ClickSend.Model;
Authorisation
Next, add your API credentials so you can use the ClickSend API in your project.
In the following snippet, simply replace the USERNAME
and API_KEY
placeholders with your own Username and API Key. These can be found on your Dashboard here.
var configuration = new Configuration()
{
Username = USERNAME,
Password = API_KEY
};
Create an instance of the API class
The following snippet of code will create an instance of the SMSApi class, which is configured to work with the credentials that we set up in the previous step. This instance will be called in the following steps, allowing you to interact with ClickSend’s SMS-related functionality.
var smsApi = new SMSApi(configuration);
Configure your message
It’s time to configure the content of your message and specify who you’re sending to. This code includes everything that you need to send an SMS message. To see what other parameters you can include, see our full API reference.
Now, it’s a simple matter of a few tweaks:
- Replace SOURCE with your preferred source (eg. the name of your application). This is not seen by recipients, but will help you to identify messages sent from various applications.
- Replace MESSAGE with your own message.
- Replace TO_PHONE_NUMBER with your own mobile number, including country code. For example, if you have an Australian number, it will start with +61.
var listOfSms = new List<SmsMessage>
{
new SmsMessage(
source: "SOURCE",
body: "MESSAGE",
to: "TO_PHONE_NUMBER"
)
};
Create an SMS message collection
Next, we will create a collection using the SmsMessage
object that we just configured as a parameter.
var smsCollection = new SmsMessageCollection(listOfSms);
Send SMS message
Finally, try to call the SmsSendPost
method using the smsApi
instance you created earlier.
var response = smsApi.SmsSendPost(smsCollection);