TextCus API Documentation
  • Introduction
  • OVERVIEW
    • Send SMS
      • Quick Send
      • Send Multiple SMS
    • Sender IDs
      • List Senders
      • Add Senders
    • Account Balance
    • One Time Password (OTP)
Powered by GitBook
On this page
  • Endpoint
  • Headers
  • Request Parameters
  • Sample Requests
  • Sample Response
  1. OVERVIEW
  2. Send SMS

Quick Send

The HTTP API enables you to send SMS quickly. To send an SMS, simply call the following URL with the relevant parameters appended to the URL, as shown below:

https://sms.textcus.com/api/v2/send?destination={recipient}&source={sender}&dlr={0}&type={0}&message={message}

NB: Please remove the curly bracket in the URL when testing

Endpoint

GET https://sms.textcus.com/api/v2/send

Headers

Authorization: Bearer API_KEY

Request Parameters

Below is a list of parameters when issuing an HTTP Request.

Parameters
Type
Description

type

Required

It indicates the type of message. Values for "type" include: 0 : Plain text (GSM 3.38 Character encoding) 1 : Flash (GSM 3.38 Character encoding) 2 : Unicode 3 : Reserved 5 : Plain text (ISO-8859-1 Character encoding) 6 : Unicode Flash 7 : Flash (ISO-8859-1 Character encoding)

source

Required

The source address that should appear in the message. - Max Length of 18 if numeric. - Max Length of 11 if alphanumeric. To prefix the plus sign (+) to the sender’s address when the message is displayed on their mobile phone, please prefix the plus sign to your sender’s address while submitting the message. Note: You need to URL encode the plus sign. The SMSC may enforce additional restrictions on this field.

destination

Required

Recipient phone number Must be a valid MSIDSN Must be in the international telephone number format (may or may not include a plus [+] sign) symbol. e.g. 233241234567 or +233241234567 Multiple mobile numbers need to be separated by a comma (,) (the comma should be URL encoded).

dlr

Required

Indicates whether the client wants a delivery report for this message. The values for "dlr" include: 0 : No delivery report required 1 : Delivery report required

message

Required

The message to be sent. Must be URL encoded.

time

Optional

To schedule the message to be sent sometime or date in the future Format: YYYY-MM-DD HH:MM:SS or UNIX TIMESTAMP The Scheduled time must be at least 10 minutes ahead of the current time in UTC

Sample Requests

<?php

$data = [
  'destination' => $recipient,
  'source' => $sender,
  'dlr' => 0,
  'type' => 0,
  'message' => $message
];

$url = 'https://sms.textcus.com/api/v2/send';

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer API_KEY',  // Replace 'API_KEY' with your actual API key
    'Content-Type: application/json' 
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

?>
const axios = require('axios');

const recipient = 'RECIPIENT_NUMBER'; // Replace with the recipient's phone number
const sender = 'SENDER_NAME'; // Replace with the sender name
const message = 'YOUR_MESSAGE'; // Replace with the message to be sent

const data = {
  destination: recipient,
  source: sender,
  dlr: 0,
  type: 0,
  message: message
};

const url = 'https://sms.textcus.com/api/v2/send';

axios({
  method: 'post',
  url: url,
  data: data,
  headers: {
    'Authorization': 'Bearer API_KEY',  // Replace 'API_KEY' with your actual API Key
    'Content-Type': 'application/json'
  },
  timeout: 30000  // Set timeout to 30 seconds
})
  .then(response => {
    console.log(response.data);  // Handle successful response
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);  // Handle errors
  });
import requests
import json

# Replace with your actual values
recipient = 'RECIPIENT_NUMBER'
sender = 'SENDER_NAME'
message = 'YOUR_MESSAGE'

url = 'https://sms.textcus.com/api/v2/send'

data = {
    'destination': recipient,
    'source': sender,
    'dlr': 0,
    'type': 0,
    'message': message
}

headers = {
    'Authorization': 'Bearer API_KEY',  # Replace 'API_KEY' with your actual API Key
    'Content-Type': 'application/json'
}

try:
    response = requests.post(url, data=json.dumps(data), headers=headers, timeout=30)
    
    if response.status_code == 200:
        print(response.json())  # Handle successful response
    else:
        print(f"Failed to send message. Status code: {response.status_code}")
        print(response.text)  # Print the error message from the response

except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")
import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  String recipient = 'RECIPIENT_NUMBER'; // Replace with the recipient's phone number
  String sender = 'SENDER_NAME'; // Replace with the sender name
  String message = 'YOUR_MESSAGE'; // Replace with the message to be sent

  String url = 'https://sms.textcus.com/api/v2/send';

  Map<String, dynamic> data = {
    'destination': recipient,
    'source': sender,
    'dlr': 0,
    'type': 0,
    'message': message
  };

  try {
    final response = await http.post(
      Uri.parse(url),
      headers: {
        'Authorization': 'Bearer API_KEY', // Replace 'API_KEY' with your actual API Key
        'Content-Type': 'application/json',
      },
      body: jsonEncode(data), // Convert the data map to a JSON string
    );

    if (response.statusCode == 200) {
      print(response.body); // Handle successful response
    } else {
      print('Failed to send message. Status code: ${response.statusCode}');
      print(response.body); // Print the error message from the response
    }
  } catch (e) {
    print('Error: $e');
  }
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SendSMS {

    public static void main(String[] args) {
        String recipient = "RECIPIENT_NUMBER"; // Replace with the recipient's phone number
        String sender = "SENDER_NAME"; // Replace with the sender name
        String message = "YOUR_MESSAGE"; // Replace with the message to be sent

        String url = "https://sms.textcus.com/api/v2/send";

        Map<String, Object> data = new HashMap<>();
        data.put("destination", recipient);
        data.put("source", sender);
        data.put("dlr", 0);
        data.put("type", 0);
        data.put("message", message);

        try {
            // Convert the data map to JSON string using Jackson ObjectMapper
            ObjectMapper objectMapper = new ObjectMapper();
            String requestBody = objectMapper.writeValueAsString(data);

            // Create an HttpClient
            HttpClient client = HttpClient.newHttpClient();

            // Build the HTTP request
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create(url))
                    .header("Authorization", "Bearer API_KEY")  // Replace 'API_KEY' with your actual API Key
                    .header("Content-Type", "application/json")
                    .POST(BodyPublishers.ofString(requestBody, StandardCharsets.UTF_8))
                    .build();

            // Send the request and get the response
            HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

            // Handle response
            if (response.statusCode() == 200) {
                System.out.println("Response: " + response.body());
            } else {
                System.out.println("Failed to send message. Status code: " + response.statusCode());
                System.out.println("Response: " + response.body());
            }
        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());
        }
    }
}
Imports System.Net.Http
Imports System.Text
Imports Newtonsoft.Json

Module SendSMS
    Sub Main()
        Dim recipient As String = "RECIPIENT_NUMBER" ' Replace with the recipient's phone number
        Dim sender As String = "SENDER_NAME" ' Replace with the sender name
        Dim message As String = "YOUR_MESSAGE" ' Replace with the message to be sent

        Dim url As String = "https://sms.textcus.com/api/v2/send"

        ' Prepare the data to be sent
        Dim data As New Dictionary(Of String, Object) From {
            {"destination", recipient},
            {"source", sender},
            {"dlr", 0},
            {"type", 0},
            {"message", message}
        }

        ' Convert data to JSON string
        Dim jsonData As String = JsonConvert.SerializeObject(data)

        ' Create HttpClient
        Using client As New HttpClient()
            client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY") ' Replace 'API_KEY' with your actual API key
            client.DefaultRequestHeaders.Add("Content-Type", "application/json")

            ' Create HttpContent from JSON data
            Dim content As New StringContent(jsonData, Encoding.UTF8, "application/json")

            Try
                ' Send the POST request
                Dim response As HttpResponseMessage = client.PostAsync(url, content).Result

                ' Check the status code
                If response.IsSuccessStatusCode Then
                    ' Read the response content
                    Dim responseBody As String = response.Content.ReadAsStringAsync().Result
                    Console.WriteLine("Response: " & responseBody)
                Else
                    Console.WriteLine("Failed to send message. Status code: " & response.StatusCode)
                    Console.WriteLine("Response: " & response.Content.ReadAsStringAsync().Result)
                End If

            Catch ex As Exception
                Console.WriteLine("Error: " & ex.Message)
            End Try
        End Using
    End Sub
End Module

Sample Response

{
    "status": 200,
    "message": "Message sent successfully"
}
{
    "status": 401,
    "error": "Authentication invalid"
}, 

{
    "status": 401,
    "error": "Unauthorized: Invalid API Key"
}
PreviousSend SMSNextSend Multiple SMS

Last updated 8 months ago