Send Single SMS
Sending a single SMS is very easy and should take just a few seconds to integrate.
Using the Connect Client Libraries
Section titled “Using the Connect Client Libraries”The easiest way to send SMS is using our official client libraries.
// Inject IConnectSms via dependency injection, or build manually:// var smsClient = new ConnectClientBuilder()// .WithApiKey("your-api-key")// .BuildSmsClient();
await smsClient.SendSmsAsync(new ConnectSmsMessage{ To = "+447700900123", // Required: E.164 format From = "YourSender", // Optional if DefaultSmsSender is configured Content = "Your verification code is 123456"});Additional options
Section titled “Additional options”await smsClient.SendSmsAsync(new ConnectSmsMessage{ To = "+447700900123", Content = "Your appointment is tomorrow at 10am",
// Schedule for later (optional) DateSendAtUtc = DateTime.UtcNow.AddHours(1),
// Track an individual message for delivery receipts (optional) ClientReference = "appointment-reminder-123",
// Group sends together for usage reporting (optional) ClientTag = "acme-corp",
// Automatically shorten links in the message (optional) EnableLinkShortening = true,
// Control unicode handling (optional, defaults to Allow) Unicode = UnicodeMode.Allow // Allow, Deny, or Strip});Using templates
Section titled “Using templates”await smsClient.SendSmsAsync(new ConnectSmsMessage{ To = "+447700900123", TemplateName = "verification-code", TemplateData = new Dictionary<string, object> { ["code"] = "123456", ["expiresIn"] = "10 minutes" }});import { ConnectClient } from '@divergent/connect';
const client = new ConnectClient({ apiKey: process.env.DIVERGENT_CONNECT_API_KEY, defaultSmsSender: 'YourSender'});
const result = await client.sms.send({ to: '+447700900123', // Required: E.164 format from: 'YourSender', // Optional if defaultSmsSender is configured content: 'Your verification code is 123456'});
console.log('Message ID:', result.id);console.log('Country code:', result.countryCode);Additional options
Section titled “Additional options”const result = await client.sms.send({ to: '+447700900123', content: 'Your appointment is tomorrow at 10am',
// Schedule for later (optional) sendAt: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now
// Track an individual message for delivery receipts (optional) clientReference: 'appointment-reminder-123',
// Group sends together for usage reporting (optional) clientTag: 'acme-corp',
// Automatically shorten links in the message (optional) enableLinkShortening: true,
// Control unicode handling (optional) unicode: 'allow' // 'allow', 'deny', or 'strip'});Using templates
Section titled “Using templates”const result = await client.sms.send({ to: '+447700900123', templateName: 'verification-code', templateData: { code: '123456', expiresIn: '10 minutes' }});REST API Reference
Section titled “REST API Reference” POST /sms/send
POST
/sms/send
Request Data
Section titled “Request Data”Headers
X-Api-Key
required
string
The API Key for your Workspace.
JSON Data
sender
required
string
Sender Name for the SMS.
recipient
required
string
format: E.164 Recipient Number (E.164 format) for the SMS.
content
string
The Content of the SMS to send. Required unless templateName is provided.
templateName
string
format: max 64 chars The name of an approved template to use instead of providing content directly. Cannot be combined with content.
templateData
object
A JSON object of values to render into the template (or into ad-hoc content). Keys are referenced from within the template.
clientReference
string
Your own reference for this message. Returned on delivery receipt webhooks so you can correlate events.
clientTag
string
A grouping tag used for usage reporting — typically a reseller's end client. Normalized to lowercase a–z, 0–9 and hyphens (max 64 chars).
enableLinkShortening
boolean
Automatically shorten links in the message body. Defaults to the Workspace setting if omitted.
unicode
string
format: Allow | Deny | Strip How to handle unicode characters: Allow (default), Deny (reject the request) or Strip (remove unsupported characters).
sendAtUtc
string
format: date-time (ISO 8601) The date (UTC) in ISO 8601 format for when the SMS should be scheduled. If not specified, the SMS will be sent immediately.
Response Data
Section titled “Response Data”JSON Data
id
string
format: long / int64 The SMS ID from Connect.
countryCode
string
Country code extracted from the phone number.
Integration Sample
Section titled “Integration Sample”Paste this in your favourite terminal to send your first SMS. Don’t forget to replace the things.
curl -X POST https://connect-api.divergent.cloud/sms/send \-H "X-Api-Key: { API_KEY }" \--json '{ "sender": "{ SENDER_NAME }", "recipient": "{ RECIPIENT_NUMBER }", "content": "{ CONTENT }", "clientTag": "{ CLIENT_TAG }"}'<?php$data = array( 'sender' => '{ SENDER_NAME }', 'recipient' => '{RECIPIENT_NUMBER}', 'content' => '{ CONTENT }', 'clientTag' => '{ CLIENT_TAG }');$api_key = '{ API_KEY }';$json_data = json_encode($data);$ch = curl_init('https://connect-api.divergent.cloud/sms/send');curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($json_data), 'X-API-Key: ' . $api_key));
$response = curl_exec($ch);if (curl_errno($ch)) { throw new Exception(curl_error($ch));}curl_close($ch);