SMSAPI.pl 3.0.0

dotnet add package SMSAPI.pl --version 3.0.0
                    
NuGet\Install-Package SMSAPI.pl -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SMSAPI.pl" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SMSAPI.pl" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SMSAPI.pl" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SMSAPI.pl --version 3.0.0
                    
#r "nuget: SMSAPI.pl, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SMSAPI.pl@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SMSAPI.pl&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SMSAPI.pl&version=3.0.0
                    
Install as a Cake Tool

SMSAPI C# client

NuGet

Client library for the SMSAPI messaging platform. Works with smsapi.io, smsapi.pl and smsapi.com accounts.

Requirements

  • .NET 6.0 or newer (net6.0, net7.0, net8.0, net9.0, net10.0)

Dependencies

Installed automatically by NuGet:

No other third-party packages are required. HTTP communication uses the built-in System.Net.Http.HttpClient.

Installation

dotnet add package SMSAPI.pl

or in Package Manager Console:

Install-Package SMSAPI.pl

Quick start

using SMSApi.Api;

var client = new ClientOAuth("token");
var features = new Features(client);

var result = features.SMS()
    .ActionSend("4850010010", "Hello world")
    .SetSender("Test")
    .Execute();

Console.WriteLine($"Sent: {result.Count}");

More examples for every feature are in the examples/ directory.

Authentication

Only OAuth bearer tokens are supported. Generate a token in the SMSAPI panel (smsapi.pl / smsapi.com) and pass it to ClientOAuth:

var client = new ClientOAuth("token");

Basic (username/password) authentication was removed in 3.0.

How to pick a service?

Features (and every *Factory) accepts a ProxyAddress. Default is smsapi.io.

var features = new Features(client);                          // smsapi.io (default)
var features = new Features(client, ProxyAddress.SmsApiPl);   // api.smsapi.pl
var features = new Features(client, ProxyAddress.SmsApiCom);  // api.smsapi.com

Backup endpoints ProxyAddress.BackupSmsApiPl and ProxyAddress.BackupSmsApiCom are available as well.

Features

Every feature is reached through an extension method on Features:

Feature Accessor Examples
SMS (send, get status, delete scheduled, fallback, templates) features.SMS() examples/sms
MMS features.MMS() examples/mms
VMS (text-to-speech, audio file) features.VMS() examples/vms
HLR lookups features.HLR() examples/hlr
MFA codes features.MFA() examples/mfa
Sender names features.Sendernames() examples/sendernames
Short URLs features.ShortUrl() examples/shortUrl
Contacts, groups, fields features.Contacts() examples/contacts
Subusers features.Subusers() examples/subusers
Blacklist features.Blacklist() examples/blacklist
Opt-out features.OptOut() examples/optOut
Profile, points features.Profile() examples/profile
Prices features.Prices() examples/profile/prices
Ping features.Ping() examples/ping

Listings support pagination through Limit / Offset — see examples/Pagination.cs.

Async

Every action can be executed asynchronously:

var result = await features.SMS()
    .ActionSend("4850010010", "Hello world")
    .ExecuteAsync(cancellationToken);

Custom HttpClient and proxy

By default the library creates its own HttpClient. To reuse your own instance (e.g. configured with a web proxy, timeouts or IHttpClientFactory), pass it to Features:

var httpClient = new HttpClient(new HttpClientHandler
{
    Proxy = new WebProxy("http://proxy.example.com:8080"),
});

var features = new Features(client, httpClient, ProxyAddress.SmsApiPl);

To point the client at a different base URL (e.g. a test environment), build the transport yourself:

var proxy = new ProxyHTTP("https://api.example.com", httpClient);
var features = new Features(client, proxy);

Error handling

All API errors derive from SmsapiException, which exposes the error Code and, where available, the raw API Response.

try
{
    var result = features.SMS()
        .ActionSend("4850010010", "Hello world")
        .Execute();
}
catch (ActionException e)
{
    // Action error, e.g. invalid sender name, empty message
    Console.WriteLine($"{e.Code}: {e.Message}");
}
catch (ClientException e)
{
    // Client error, e.g. 101 invalid token, 103 insufficient credits
    // (full list of codes in the SMSAPI docs: https://www.smsapi.pl/docs)
    Console.WriteLine($"{e.Code}: {e.Message}");
}
catch (HostException e)
{
    // Server error or malformed API response (code -1, raw body in e.Response)
    Console.WriteLine($"{e.Code}: {e.Message}");
}
catch (ProxyException e)
{
    // Communication problem between the client and the server
    Console.WriteLine(e.Message);
}

REST endpoints (contacts, sender names, short URLs, subusers, opt-out, blacklist, MFA, HLR) additionally throw typed exceptions from smsapi.Api.Response.REST.Exception — ValidationException (with ValidationErrors), NotFoundException (base for feature-specific ones like OptOutNotFoundException), UnauthorizedException, AccessForbiddenException, TooManyRequestsException, ServiceUnavailableException — and feature-specific ones such as ContactAlreadyExistsException or ShortUrlWithNameAlreadyExistsException.

Upgrading from 2.x

See CHANGELOG.md for the full list of breaking changes in 3.0.

License

Apache 2.0 License

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

3.0.0: OAuth-only authentication, RestSharp replaced with HttpClient, async support, new features (MFA, HLR, Blacklist, Opt-out, Short URLs, Subusers, Sender names, Profile, Prices, Ping), .NET 6-10. See CHANGELOG.md for breaking changes.