Skip to main content

SMS Notifications

Send SMS messages to one or more recipients using the Notifications API. This service allows you to send text messages to users directly from your application.

Prerequisites

Before sending SMS notifications, ensure you have:

  1. A valid API subscription key
  2. Permission to access the Notifications API
  3. Valid phone numbers for your recipients

Sending SMS Messages

To send an SMS message, make a POST request to the /Sms/Send endpoint with the following details:

Request Headers

HeaderDescriptionRequired
correlationidUnique identifier for tracking the requestYes
x-ls-party-idParty identifierYes
Ocp-Apim-Subscription-KeyYour API subscription keyYes

Request Body

The request body requires:

  • body: The text content of the SMS message
  • sendTo: An array of recipients, each with:
    • address: The recipient's phone number
    • countryCode: The country code for the phone number

Code Examples

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class SmsClient
{
private readonly HttpClient _client;
private readonly string _baseUrl = "https://apis.lightstone.co.za/lightstone-capabilities-notifications-api/v1";

public SmsClient(string apiKey)
{
_client = new HttpClient();
_client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
}

public async Task<SmsResponse> SendSmsAsync(string message, string correlationId, string partyId,
params (string phoneNumber, string countryCode)[] recipients)
{
var request = new
{
body = message,
sendTo = Array.ConvertAll(recipients, r => new
{
address = r.phoneNumber,
countryCode = r.countryCode
})
};

var content = new StringContent(
JsonSerializer.Serialize(request),
Encoding.UTF8,
"application/json");

_client.DefaultRequestHeaders.Add("correlationid", correlationId);
_client.DefaultRequestHeaders.Add("x-ls-party-id", partyId);

var response = await _client.PostAsync($"{_baseUrl}/Sms/Send", content);
var responseContent = await response.Content.ReadAsStringAsync();

return JsonSerializer.Deserialize<SmsResponse>(responseContent);
}
}

public class SmsResponse
{
public int StatusCode { get; set; }
public string Message { get; set; }
}

Response Handling

The API returns a JSON response with the following structure:

{
"statusCode": 0,
"message": "SMS sent successfully"
}

Status Codes

Status CodeDescription
0Success
Other valuesError codes (refer to error message for details)

Best Practices

  1. Validate Phone Numbers: Ensure phone numbers are valid before sending messages
  2. Keep Messages Concise: SMS messages have a 160 character limit per segment
  3. Handle Failures: Implement proper error handling for failed deliveries
  4. Rate Limiting: Be mindful of rate limits when sending bulk messages
  5. Compliance: Ensure your SMS messages comply with relevant regulations and laws

Troubleshooting

If you encounter issues when sending SMS notifications:

  1. Verify your API key is valid and has the necessary permissions
  2. Check that the recipient phone numbers are correctly formatted
  3. Ensure the country codes match the phone numbers
  4. Review the response message for specific error details