Skip to content

Latest commit

Β 

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ClickSend C# SDK

NuGet NuGet downloads License: MIT API: v3

Official .NET client for the ClickSend API β€” send SMS, MMS, voice and email messages, run SMS and MMS campaigns, manage numbers, contacts and subaccounts, and pull delivery receipts and reporting through a single authenticated HTTPS client.

This library is generated from ClickSend's official OpenAPI v3 specification and is maintained by ClickSend. It covers every endpoint of the ClickSend REST API.

Features

  • Messaging β€” SMS, MMS, voice / text-to-speech, transactional email, email-to-SMS
  • Campaigns β€” SMS and MMS campaigns
  • Numbers & sender IDs β€” dedicated numbers, own numbers, alpha tags, default senders
  • Contacts β€” contact lists, contacts and the address book
  • Account & billing β€” account details, transactions, subaccounts, referrals, reseller accounts
  • Delivery & reporting β€” delivery receipts, inbound messages, statistics
  • Extras β€” URL shortening, file uploads, number verification, international messaging
  • Typed models for every request and response, with async methods throughout
  • HTTP Basic auth with your ClickSend username and API key
  • Identifiable traffic β€” requests are sent with a ClickSend-SDK/<version>/csharp User-Agent by default
  • MIT licensed

Requirements

  • .NET 10.0 or newer

Installation

dotnet add package ClickSend

Authentication

Every API class authenticates with HTTP Basic auth using your ClickSend username and API key, both available from the ClickSend Dashboard. Supply them through environment variables rather than hard-coding them:

export CLICKSEND_USERNAME="your-username"
export CLICKSEND_API_KEY="your-api-key"

Quickstart

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using ClickSend.Api;
using ClickSend.Client;
using ClickSend.Extensions;
using ClickSend.Model;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureApi((context, services, options) =>
    {
        BasicToken token = new(
            Environment.GetEnvironmentVariable("CLICKSEND_USERNAME"),
            Environment.GetEnvironmentVariable("CLICKSEND_API_KEY"));
        options.AddTokens(token);
    })
    .Build();

var smsApi = host.Services.GetRequiredService<ISmsApi>();

var sendSmsRequest = new SendSmsRequest(
    messages: new List<SendSmsRequestMessagesInner>
    {
        new(body: "Hello from ClickSend!", to: "+61411111111", source: "sdk")
    });

ISendSmsApiResponse response = await smsApi.SendSmsAsync(sendSmsRequest: sendSmsRequest);
SendSms? result = response.Ok();

More Examples

View account details

var managementApi = host.Services.GetRequiredService<IManagementApi>();
IViewAccountDetailsApiResponse response = await managementApi.ViewAccountDetailsAsync();
ViewAccountDetails? account = response.Ok();

Send an MMS

var mmsApi = host.Services.GetRequiredService<IMmsApi>();

var sendMmsRequest = new SendMmsRequest(
    mediaFile: "https://clicksend.com/logo.png",
    messages: new List<SendMmsRequestMessagesInner>
    {
        new(to: "+61411111111", from: "sdk", subject: "Hello", body: "Hello from ClickSend!", source: "sdk")
    });

ISendMmsApiResponse response = await mmsApi.SendMmsAsync(sendMmsRequest: sendMmsRequest);
SendMms? result = response.Ok();

Configuration

The base URL defaults to https://rest.clicksend.com. Override it, along with the HttpClient and its handlers, from the ConfigureApi builder:

.ConfigureApi((context, services, options) =>
{
    options.AddTokens(new BasicToken(username, apiKey));
})
.ConfigureHttpClients((context, services, builder) =>
{
    builder.ConfigureHttpClient(client =>
    {
        client.BaseAddress = new Uri("https://rest.clicksend.com");
        client.Timeout = TimeSpan.FromSeconds(30);
    });
});

Error Handling

Call response.Ok() for the deserialized success payload, or inspect the response for failures:

ISendSmsApiResponse response = await smsApi.SendSmsAsync(sendSmsRequest: sendSmsRequest);

if (response.IsSuccessStatusCode)
{
    SendSms? result = response.Ok();
}
else
{
    // response.StatusCode  β€” HTTP status code
    // response.RawContent  β€” raw error payload from the API
}

Documentation

Versioning

This package follows semantic versioning. Breaking changes are released as major versions.

Support

License

Released under the MIT License.


Keywords: clicksend, sms, sms api, send sms, bulk sms, text message, texting, mms, mms api, voice, voice call, text to speech, tts, ivr, email to sms, sms campaign, mms campaign, url shortening, number verification, messaging, notifications, otp, 2fa, two factor authentication, transactional sms, marketing sms, appointment reminders, alerts, csharp, dotnet, netstandard, rest api, clicksend sdk

About

Repo for a new and improved csharp SDKs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages