Skip to main content

Java Examples for adaline.ink

Java code examples for the Adaline platform API using HttpClient.

Examples use Java 11+ HttpClient. No external dependencies.

Setup

import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;
import java.nio.file.*;

public class AdalineClient {
    private static final String BASE_URL = "https://api.adaline.ink";
    private static final HttpClient client = HttpClient.newHttpClient();
    private static String accessToken = "";

    static String apiRequest(String method, String path, String body) throws Exception {
        var builder = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + path))
            .header("Authorization", "Bearer " + accessToken)
            .header("Content-Type", "application/json");

        switch (method) {
            case "POST" -> builder.POST(body != null ? BodyPublishers.ofString(body) : BodyPublishers.noBody());
            case "DELETE" -> builder.DELETE();
            case "PATCH" -> builder.method("PATCH", body != null ? BodyPublishers.ofString(body) : BodyPublishers.noBody());
            default -> builder.GET();
        }

        return client.send(builder.build(), HttpResponse.BodyHandlers.ofString()).body();
    }
}

Authentication

static void login(String email, String password) throws Exception {
    String body = String.format("{\"email\":\"%s\",\"password\":\"%s\"}", email, password);
    var request = HttpRequest.newBuilder()
        .uri(URI.create(BASE_URL + "/api/v1/auth/login"))
        .header("Content-Type", "application/json")
        .POST(BodyPublishers.ofString(body))
        .build();
    String response = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
    // Parse access_token from JSON response
    accessToken = response.split("\"access_token\":\"")[1].split("\"")[0];
}

public static void main(String[] args) throws Exception {
    login("you@example.com", "your-password");
}

Upload a Document

static String uploadDocument(String orgId, String filePath) throws Exception {
    String boundary = "----Boundary" + System.currentTimeMillis();
    byte[] fileBytes = Files.readAllBytes(Path.of(filePath));
    String fileName = Path.of(filePath).getFileName().toString();

    String prefix = "--" + boundary + "\r\n"
        + "Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"\r\n"
        + "Content-Type: application/octet-stream\r\n\r\n";
    String suffix = "\r\n--" + boundary + "--\r\n";

    byte[] body = new byte[prefix.getBytes().length + fileBytes.length + suffix.getBytes().length];
    System.arraycopy(prefix.getBytes(), 0, body, 0, prefix.getBytes().length);
    System.arraycopy(fileBytes, 0, body, prefix.getBytes().length, fileBytes.length);
    System.arraycopy(suffix.getBytes(), 0, body, prefix.getBytes().length + fileBytes.length, suffix.getBytes().length);

    var request = HttpRequest.newBuilder()
        .uri(URI.create(BASE_URL + "/api/v1/documents/upload?org_id=" + orgId))
        .header("Authorization", "Bearer " + accessToken)
        .header("Content-Type", "multipart/form-data; boundary=" + boundary)
        .POST(BodyPublishers.ofByteArray(body))
        .build();

    return client.send(request, HttpResponse.BodyHandlers.ofString()).body();
}

Compliance Check

String report = apiRequest("POST", "/api/v1/compliance/test",
    "{\"document_id\": \"" + docId + "\"}");
System.out.println(report);

Start Conversion

String job = apiRequest("POST", "/api/v1/conversions/",
    "{\"document_id\": \"" + docId + "\"}");
System.out.println(job);

// Poll for status
String status = apiRequest("GET", "/api/v1/conversions/" + jobId, null);
System.out.println(status);

Tags and Sharing

// Create tag
String tag = apiRequest("POST", "/api/v1/tags",
    "{\"name\":\"reviewed\",\"color\":\"green\",\"org_id\":\"" + orgId + "\"}");

// Public share
String share = apiRequest("POST",
    "/api/v1/documents/" + docId + "/public-share", "{}");
System.out.println(share);
© 2026 Adaline LLC