Skip to Content
SDKsJava

Java SDK

A Java client built on OkHttp and Gson, usable from Kotlin and any JVM language. It requires Java 8 or later.

<!-- Maven --> <dependency> <groupId>dev.licensemanager</groupId> <artifactId>licensemanager-java</artifactId> <version>LATEST_VERSION</version> </dependency>
// Gradle implementation("dev.licensemanager:licensemanager-java:LATEST_VERSION")

Maven Central  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicensesApi or CustomersApi, and one method per endpoint, named after it: Create a license is createLicense. A method takes the path parameters and the body, and returns a request: set its optional parameters with its methods, then send it with execute(), which returns the response as a model.

The API Reference lists every endpoint with its parameters and response: the SDK’s methods take and return the same ones.

Authentication

Set the credentials on the ApiClient the classes use:

import dev.licensemanager.ApiClient; import dev.licensemanager.api.LicensesApi; ApiClient client = new ApiClient(); // With an API key, from your backend: client.setApiKey(System.getenv("LICENSEMANAGER_API_KEY")); // Or with a token scoped to a customer, license or machine: client.setBearerToken(token); LicensesApi licenses = new LicensesApi(client);

Never ship an API key in your application: anyone could extract it. Keep it on your servers.

Examples

Create a license after a sale, and email its key to the customer:

License license = licenses.createLicense( "x7Kp2QaZ", new CreateLicense().email("jane@example.com").sendKey(true)) .execute();

Validate a key from your application, which needs no credentials:

LicenseToken licenseToken = new LicensesApi().validateKey( "x7Kp2QaZ", new ValidateKey() .key("7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF") .fingerprint("4c:32:75:8f:9a:1e") .version("1.4.2")) .execute(); // licenseToken.getLicense() is the signed license token.

List the licenses of a product, one page at a time:

LicenseList page = licenses.listLicenses("x7Kp2QaZ") .page(2) .pageSize(50) .sort("-createdAt") .execute(); // page.getData() holds the licenses, page.getPagination() the totals.

Errors

A failed request throws an ApiException, holding the status and the body with the error’s stable code:

import dev.licensemanager.ApiException; try { licenses.getLicense("l3Nv8KwB").execute(); } catch (ApiException error) { // The body is { "error": { "code", "message" } }. System.err.println(error.getCode() + " " + error.getResponseBody()); }