Skip to content

Latest commit

Β 

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ClickSend Java SDK

Maven Central License: MIT API: v3

Official Java client for the ClickSend API β€” send SMS, MMS, voice and email messages, run SMS and MMS campaigns, manage numbers, contacts and subaccounts, and pull delivery receipts and reporting through a single authenticated HTTPS client.

This library is generated from ClickSend's official OpenAPI v3 specification and is maintained by ClickSend. It covers every endpoint of the ClickSend REST API.

Features

  • Messaging β€” SMS, MMS, voice / text-to-speech, transactional email, email-to-SMS
  • Campaigns β€” SMS and MMS campaigns
  • Numbers & sender IDs β€” dedicated numbers, own numbers, alpha tags, default senders
  • Contacts β€” contact lists, contacts and the address book
  • Account & billing β€” account details, transactions, subaccounts, referrals, reseller accounts
  • Delivery & reporting β€” delivery receipts, inbound messages, statistics
  • Extras β€” URL shortening, file uploads, number verification, international messaging
  • Typed models for every request and response
  • HTTP Basic auth with your ClickSend username and API key
  • Identifiable traffic β€” requests are sent with a ClickSend-SDK/<version>/java User-Agent by default
  • MIT licensed

Requirements

  • Java 1.8 or newer
  • Maven (3.8.3+) or Gradle (7.2+)

Installation

Maven

<dependency>
  <groupId>com.clicksend</groupId>
  <artifactId>clicksend-java</artifactId>
  <version>6.0.3</version>
</dependency>

Gradle

implementation "com.clicksend:clicksend-java:6.0.3"

Authentication

Every API class authenticates with HTTP Basic auth using your ClickSend username and API key, both available from the ClickSend Dashboard. Supply them through environment variables rather than hard-coding them:

export CLICKSEND_USERNAME="your-username"
export CLICKSEND_API_KEY="your-api-key"

Quickstart

import ClickSend.ApiClient;
import ClickSend.ApiException;
import ClickSend.Configuration;
import ClickSend.auth.*;
import ClickSend.Api.SmsApi;
import ClickSend.Model.*;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        HttpBasicAuth basicAuth = (HttpBasicAuth) defaultClient.getAuthentication("basicAuth");
        basicAuth.setUsername(System.getenv("CLICKSEND_USERNAME"));
        basicAuth.setPassword(System.getenv("CLICKSEND_API_KEY"));

        SmsApi apiInstance = new SmsApi(defaultClient);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
            .addMessagesItem(new SendSmsRequestMessagesInner()
                .body("Hello from ClickSend!")
                .to("+61411111111")
                .source("sdk"));

        try {
            // The first argument is the optional `contentType` header β€” pass `null` to use the default.
            // The request body is the second argument.
            SendSms result = apiInstance.sendSms(null, sendSmsRequest);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling SmsApi#sendSms: " + e.getMessage());
        }
    }
}

More Examples

View account details

import ClickSend.Api.ManagementApi;
import ClickSend.Model.ViewAccountDetails;

ManagementApi managementApi = new ManagementApi(defaultClient);

try {
    ViewAccountDetails account = managementApi.viewAccountDetails(null);
    System.out.println(account);
} catch (ApiException e) {
    System.err.println("Exception when calling ManagementApi#viewAccountDetails: " + e.getMessage());
}

Send an MMS

import ClickSend.Api.MmsApi;
import ClickSend.Model.SendMms;
import ClickSend.Model.SendMmsRequest;
import ClickSend.Model.SendMmsRequestMessagesInner;

MmsApi mmsApi = new MmsApi(defaultClient);
SendMmsRequest sendMmsRequest = new SendMmsRequest()
    .mediaFile("https://clicksend.com/logo.png")
    .addMessagesItem(new SendMmsRequestMessagesInner()
        .to("+61411111111")
        .from("sdk")
        .subject("Hello")
        .body("Hello from ClickSend!")
        .source("sdk"));

try {
    // As with sendSms, the first argument is the optional `contentType` header β€” pass `null`.
    SendMms result = mmsApi.sendMms(null, sendMmsRequest);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling MmsApi#sendMms: " + e.getMessage());
}

Configuration

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Override the API base URL (default: https://rest.clicksend.com).
defaultClient.setBasePath("https://rest.clicksend.com");

// Connect / read timeouts, in milliseconds.
defaultClient.setConnectTimeout(10_000);
defaultClient.setReadTimeout(30_000);

Error Handling

Non-2xx responses throw ClickSend.ApiException:

try {
    SendSms result = apiInstance.sendSms(null, sendSmsRequest);
} catch (ApiException e) {
    e.getCode();            // HTTP status code
    e.getResponseBody();    // raw error payload from the API
    e.getResponseHeaders(); // response headers
}

Documentation

Versioning

This package follows semantic versioning. Breaking changes are released as major versions.

Support

License

Released under the MIT License.


Keywords: clicksend, sms, sms api, send sms, bulk sms, text message, texting, mms, mms api, voice, voice call, text to speech, tts, ivr, email to sms, sms campaign, mms campaign, url shortening, number verification, messaging, notifications, otp, 2fa, two factor authentication, transactional sms, marketing sms, appointment reminders, alerts, java, jvm, rest api, clicksend sdk

About

Repo for a new and improved java SDKs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages