Java SDK

Installation

The recommended way to install the Unimatrix SDK for Java is with a dependency management tool such as Maven or Gradle, which is available on Maven Central.

Maven users

Add this dependency to your project's pom.xml file:

<dependency>
    <groupId>com.unimtx</groupId>
    <artifactId>uni-sdk</artifactId>
    <version>0.2.0</version>
</dependency>

Gradle users

Add this dependency to your project's build.gradle file:

implementation "com.unimtx:uni-sdk:0.2.0"

Usage

The following example shows how to use the Unimatrix Java SDK to interact with Unimatrix services.

Send SMS

Send a text message to a single recipient.


import com.unimtx.Uni;
import com.unimtx.UniException;
import com.unimtx.UniResponse;
import com.unimtx.model.UniMessage;

public class Example {
    public static String ACCESS_KEY_ID = "your access key id";
    private static String ACCESS_KEY_SECRET = "your access key secret";

    public static void main(String[] args) {
        // initialization
        Uni.init(ACCESS_KEY_ID, ACCESS_KEY_SECRET); // if you use the simple auth mode, just pass in the first parameter

        // build a message
        UniMessage message = UniMessage.buildMessage()
            .setTo("your phone number") // in E.164 format
            .setText("Your verification code is 2048.");

        // send the message
        try {
            UniResponse res = message.send();
            System.out.println(res.data);
        } catch (UniException e) {
            System.out.println("Error: " + e);
            System.out.println("RequestId: " + e.requestId);
        }
    }
}

Send a message using a template with variables.

Map<String, String> templateData = new HashMap<String, String>();
templateData.put("code", "2048");

UniMessage.buildMessage()
    .setTo("+1650253xxxx")
    .setSignature("Unimatrix")
    .setTemplateId("pub_verif_en_basic2")
    .setTemplateData(templateData)
    .send();