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 for billing/analytics (optional) ClientReference = "appointment-reminder-123",
// Control unicode handling (optional, defaults to Allow) UnicodeMode = 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 for billing/analytics (optional) clientReference: 'appointment-reminder-123',
// Control unicode handling (optional) unicodeMode: '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
required
string
The Content of the SMS to send.
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 }"}'<?php$data = array( 'sender' => '{ SENDER_NAME }', 'recipient' => '{RECIPIENT_NUMBER}', 'content' => '{ CONTENT }');$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);