ReachBellDocs

Server SDK (Java)

reachbell-java is the Java server-side companion to the browser SDK. Use it from your backend to send transactional messages, track events, and manage subscribers — without writing raw HTTP calls. The Server API is the underlying REST layer for endpoints the SDK doesn't wrap yet.

Java 11+. Depends only on the JDK (java.net.http.HttpClient) — no third-party libraries.

Preview — this SDK is newly released; build and run mvn test in your project before shipping.

Install

Maven:

<dependency>
    <groupId>com.reachbell</groupId>
    <artifactId>reachbell-java</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle (Kotlin DSL):

implementation("com.reachbell:reachbell-java:1.0.0")

Initialize

import com.reachbell.ReachBell;
 
ReachBell rb = new ReachBell(System.getenv("REACHBELL_API_KEY"));

Keep your API key server-side only — never ship it to the browser. The client is thread-safe and cheap to reuse — create it once (e.g. a singleton or Spring @Bean) and share it.

Transactional push

Send a push to one user, identified by externalId (set via the browser SDK's identify()) or by raw token. Requests are built with fluent builders — any field you don't set is simply omitted:

import java.util.Map;
 
Map<String, Object> r = rb.transactional.send(
    ReachBell.push()
        .externalId("user_42")
        .title("Order shipped 📦")
        .body("Your order arrives tomorrow."));
 
// A 200 with delivered=false just means the user has no active subscription —
// a normal outcome, not an error.
if (!Boolean.TRUE.equals(r.get("delivered"))) {
    // no active subscription
}

Use .templateId(...) (plus .variables(...)) instead of title/body to send from a saved template.

Transactional email

rb.transactional.email(ReachBell.email()
    .to("user@example.com")
    .subject("Your verification code")
    .htmlContent("<p>Your code is <b>123456</b></p>"));

Transactional SMS & WhatsApp

rb.transactional.sms(ReachBell.sms()
    .externalId("user_42")
    .text("Your code is 123456"));
 
rb.transactional.whatsapp(ReachBell.whatsapp()
    .externalId("user_42")
    .template("order_update", "#4821", "shipped"));

WhatsApp business-initiated messages need a pre-approved template (outside WhatsApp's 24-hour customer-service window); inside it you can send free-form .text(...). Both channels must be configured for your project first — see SMS and WhatsApp.

Track events

Events can trigger automations:

rb.events.track(ReachBell.event("order_paid")
    .externalId("user_42")
    .properties(Map.of("amount", 4999)));
 
rb.events.trackBatch(events); // List of event builders, up to 25

Subscribers

rb.subscribers.identify(token, "user_42"); // link a subscription to your user id
rb.subscribers.delete(token);              // remove a subscriber

Errors

Non-2xx responses and network/timeout failures throw com.reachbell.ReachBellException (unchecked), with getHttpStatus() (0 for network errors) and getResponseBody() (a Map for JSON, a String for non-JSON, or null):

import com.reachbell.ReachBellException;
 
try {
    rb.transactional.send(ReachBell.push().externalId("u").title("t").body("b"));
} catch (ReachBellException e) {
    System.err.println("status=" + e.getHttpStatus() + " body=" + e.getResponseBody());
}

Missing required arguments throw IllegalArgumentException before any network call.

Escape hatch

For any endpoint not yet wrapped by a helper (body may be a Map, List, or null):

Map<String, Object> out = rb.request("POST", "/some/endpoint", Map.of("any", "payload"));