Skip to main content
Version: Next

Send SMS with the SDK

Follow these steps to install the SDK, authenticate, and send SMS messages.

Before you start, you need an API username and password. See the Quickstart if you have not created them yet.

1. Install the SDK

pom.xml
<dependency>
<groupId>com.pahappa.systems</groupId>
<artifactId>comms-sdk</artifactId>
<version>1.0.2</version>
</dependency>
note

Most commands above install the latest release. A version is pinned only where the build tool requires one (Maven and Gradle). For the current version of every SDK, see the SDK Downloads page.

2. Authenticate

Main.java
import com.pahappa.systems.commssdk.v1.CommsSDK;

String apiUsername = "api_username";
String apiKey = "api_key";
CommsSDK sdk = CommsSDK.authenticate(apiUsername, apiKey);
Testing against the sandbox

The SDK targets the live server by default. If you are using sandbox credentials, switch environments before you authenticate:

LanguageCall
Java, Kotlin, JS / TS, DartCommsSDK.useSandBox()
Rust, PHPCommsSDK::use_sandbox()
Python, RubyCommsSDK.use_sandbox()
Gov1.CommsSDK.UseSandBox()
C#CommsSDK.UseSandBox()

Call useLiveServer / use_live_server to switch back. Sandbox credentials do not work against the live server, and vice versa.

3. Send SMS

There are two ways to send a message, and they take the same arguments:

  • sendSMS returns a booleantrue if the message was accepted, false if it was not.
  • querySendSMS returns an ApiResponse with the full result, including cost and messageFollowUpCode.

Both accept a single number or a list of numbers, the message text, then an optional sender ID and an optional priority. Numbers must be in international format without a leading + or 00, for example 256700111222. A single request may contain at most 1000 numbers.

Main.java
import com.pahappa.systems.commssdk.v1.models.ApiResponse;
import com.pahappa.systems.commssdk.v1.models.MessagePriority;
import java.util.List;

// one number
boolean success = sdk.sendSMS("256700111222", "Message to send");

// several numbers
List<String> numbers = List.of("256700111222", "256700333444");
sdk.sendSMS(numbers, "Message to multiple numbers");

// with a custom sender ID
sdk.sendSMS(numbers, "Message to send", "MyCompany");

// with a custom sender ID and priority
sdk.sendSMS(numbers, "Message to send", "MyCompany", MessagePriority.HIGHEST);

// full API response instead of a boolean
ApiResponse smsResponse = sdk.querySendSMS(numbers, "Query send sms message");
System.out.println(smsResponse.status);
note

For query-based methods, the returned object is of type ApiResponse. See ApiResponse.

Next steps