Developers · C#

C# SMS integration — .NET REST samples

Ready-to-use C# HTTPS/JSON examples for SMS Gateway. Any HTTP client works—you do not need a proprietary package SDK.

.NET 5+

Compatible

REST

HTTPS + JSON

Samples

Copy into your app

Overview

Quick Start Overview

Everything you need to add SMS Gateway to your .NET app

01

HTTPS + JSON samples

HttpClient patterns for the SMS Gateway REST API

02

Easy integration

Drop samples into ASP.NET, console, or worker hosts

03

Error-aware samples

Examples include basic status and exception handling

04

.NET compatibility

Works with modern .NET and common HTTP stacks

Code

C# Code Examples

Copy-paste C# code examples for all SMS Gateway features

Send SMS

POST /api/v1/messages with Bearer token and JSON { to, text }

Basic
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

public static class SmsGatewaySend
{
    // Documented send endpoint — POST /api/v1/messages (Bearer JSON)
    private const string SendUrl = "https://app.sms-gateway.app/api/v1/messages";

    public static async Task SendAsync(string apiKey, string number, string message)
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
        client.DefaultRequestHeaders.TryAddWithoutValidation("Idempotency-Key", Guid.NewGuid().ToString());

        var json = "{\"to\":[\"" + number + "\"],\"text\":\"" + message + "\",\"type\":\"sms\"}";
        using var content = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await client.PostAsync(SendUrl, content);
        var body = await response.Content.ReadAsStringAsync();
        Console.WriteLine((int)response.StatusCode + " " + body);
    }
}

Bulk SMS

Several E.164 numbers in one POST /messages (to[])

Advanced
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

public static class BulkSmsGateway
{
    private const string SendUrl = "https://app.sms-gateway.app/api/v1/messages";

    public static async Task SendManyAsync(string apiKey)
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

        var json = "{\"to\":[\"+14155552671\",\"+14155552672\"],\"text\":\"Hello from SMS Gateway!\",\"type\":\"sms\",\"dedupe\":true}";
        using var content = new StringContent(json, Encoding.UTF8, "application/json");
        var body = await (await client.PostAsync(SendUrl, content)).Content.ReadAsStringAsync();
        Console.WriteLine(body);
    }
}
Resources

Additional Resources

Everything you need to get started with C# SMS integration

01

API Documentation

REST endpoints, auth, webhooks, and status handling

Open guide
02

Webhook guide

Inbound SMS and event callbacks for your .NET app

Open guide
03

Pair a device first

Install the Android app and connect a SIM before API sends

Open guide
Get started

Ready to Integrate?

Install the Android app, pair a SIM device, then paste the API samples into your .NET backend