Official-style Java client for the Blnk Finance open-source ledger. It covers the full Core API: ledgers, balances, transactions (including bulk, inflight, and refunds), identities and tokenization, balance monitors, reconciliation, search, metadata, hooks, API keys, and system health.
- JDK 17+
- Maven 3.8+
Available on Maven Central:
<dependency>
<groupId>com.blnkfinance</groupId>
<artifactId>blnk-java</artifactId>
<version>1.7.0</version>
</dependency>Gradle:
implementation("com.blnkfinance:blnk-java:1.7.0")The only runtime dependency is Jackson Databind; HTTP uses the JDK's built-in
java.net.http.HttpClient.
To build from source:
mvn installimport com.blnkfinance.blnk.Blnk;
import com.blnkfinance.blnk.BlnkClientOptions;
import com.blnkfinance.blnk.types.ApiResponse;
import com.blnkfinance.blnk.types.CreateLedger;
import com.fasterxml.jackson.databind.JsonNode;
Blnk blnk = Blnk.init("<secret_key_if_set>",
BlnkClientOptions.builder()
.baseUrl("http://localhost:5001") // trailing "/" appended automatically
.build());
ApiResponse<JsonNode> newLedger = blnk.ledgers().create(
CreateLedger.create()
.name("Customer Savings Account")
.metaData(java.util.Map.of("project_owner", "YOUR_APP_NAME")));
System.out.println("status: " + newLedger.status()); // 201
System.out.println("message: " + newLedger.message()); // "Success"
System.out.println("ledger: " + newLedger.data()); // parsed JSON bodyCloud Proxy: same Core methods and bodies, with the Cloud proxy base URL and
instanceId. Cloud routes with instance_id (Enterprise Proxy):
Blnk blnk = Blnk.init("<cloud_api_key_or_oauth_token>",
BlnkClientOptions.builder()
.baseUrl("https://api.cloud.blnkfinance.com/proxy")
.instanceId("instance_073f7ffe-9dfd-42ce-aa50-d1dca1788adc")
.build());Use the instance id from Cloud (instance_...), not deployment_id. Self-hosted
Core clients omit instanceId.
A follow-up flow — create a balance and move money into it:
import com.blnkfinance.blnk.types.CreateLedgerBalance;
import com.blnkfinance.blnk.types.CreateTransactions;
String ledgerId = newLedger.data().get("ledger_id").asText();
ApiResponse<JsonNode> balance = blnk.ledgerBalances().create(
CreateLedgerBalance.create()
.ledgerId(ledgerId)
.currency("USD"));
ApiResponse<JsonNode> deposit = blnk.transactions().create(
CreateTransactions.create()
.amount(750)
.precision(100)
.currency("USD")
.reference("ref_001adcfgf")
.description("First deposit")
.source("@WorldUSD")
.destination(balance.data().get("balance_id").asText())
.allowOverdraft(true));Preview a post without writing it (Core 0.15.3+):
import com.blnkfinance.blnk.types.DryRunTransactionResponse;
ApiResponse<JsonNode> preview = blnk.transactions().create(
CreateTransactions.create()
.amount(120)
.precision(100)
.currency("USD")
.reference("ref_preview_001")
.source("@WorldUSD")
.destination(balance.data().get("balance_id").asText())
.dryRun(true));
DryRunTransactionResponse dryRun = DryRunTransactionResponse.fromJson(preview.data());
if (Boolean.TRUE.equals(dryRun.wouldApply())) {
System.out.println("would apply: " + dryRun.status());
} else {
System.out.println("rejected: " + dryRun.rejection().code());
}
// Advisories such as a currency mismatch arrive even when would_apply is true.
dryRun.notes().forEach(note -> System.out.println("note: " + note));Create an internal General Ledger balance:
blnk.ledgerBalances().create(
CreateLedgerBalance.create()
.ledgerId("general_ledger_id")
.currency("USD")
.indicator("@Revenue"));Search several collections in one request (POST /multi-search; results come back
in the same order as the searches):
import com.blnkfinance.blnk.types.MultiSearchParams;
import com.blnkfinance.blnk.types.SearchParams;
ApiResponse<JsonNode> results = blnk.search().multiSearch(
MultiSearchParams.create()
.add("transactions", SearchParams.create().q("ref_001").queryBy("reference"))
.add("balances", SearchParams.create().q("*").filterBy("currency:USD"))
.add("ledgers", SearchParams.create().q("savings").queryBy("name")));
JsonNode transactionHits = results.data().get("results").get(0).get("hits");Page through ledgers, balances, or transactions (Core defaults to offset=0 and a
limit of 10, or 20 for transactions):
import com.blnkfinance.blnk.types.ListOptions;
ApiResponse<JsonNode> firstPage = blnk.ledgers().list();
ApiResponse<JsonNode> nextPage = blnk.ledgers().list(
ListOptions.create().limit(10).offset(10));
ApiResponse<JsonNode> usdBalances = blnk.ledgerBalances().list(
ListOptions.create().limit(50));
ApiResponse<JsonNode> recentTransactions = blnk.transactions().list(
ListOptions.create().limit(100));identity().list() returns every identity: Core 0.15.9 ignores limit and offset
on GET /identities unless filters are also sent. To page identities, use the
filter route (POST /identities/filter), which always applies limit (1–100,
default 20) and offset:
import com.blnkfinance.blnk.types.FilterParams;
ApiResponse<JsonNode> identityPage = blnk.search().filter(
FilterParams.create().filters(java.util.List.of()).limit(20).offset(40),
"identities");Expand a balance's identity and ledger (GET /balances/:id?include=identity&include=ledger):
import com.blnkfinance.blnk.types.GetBalanceRequest;
String balanceId = balance.data().get("balance_id").asText();
ApiResponse<JsonNode> expanded = blnk.ledgerBalances().get(
balanceId,
GetBalanceRequest.create()
.include(GetBalanceRequest.INCLUDE_IDENTITY, GetBalanceRequest.INCLUDE_LEDGER));
JsonNode owner = expanded.data().get("identity");Watch a balance. The condition value is in major units, like a transaction
amount: Core stores precise_value = value × precision, so $100 on a USD
balance is value(100) with precision(100):
import com.blnkfinance.blnk.types.MonitorCondition;
import com.blnkfinance.blnk.types.MonitorData;
import com.blnkfinance.blnk.types.MonitorTrigger;
ApiResponse<JsonNode> monitor = blnk.balanceMonitor().create(
MonitorData.create()
.balanceId(balanceId)
.description("Below $100")
.callBackUrl("https://example.com/hooks/low-balance")
.condition(MonitorCondition.create()
.field("balance")
.operator("<")
.value(100) // $100, not 10000
.precision(100))
.trigger(MonitorTrigger.EDGE)); // the default: alert once per crossing.
// LEVEL alerts on every update while it holds.Change a monitor with updatePartial (Core 0.15.9+). Only the fields you set are
sent, and Core keeps the rest. The callback URL can't be changed after creation:
import com.blnkfinance.blnk.types.UpdateMonitorData;
String monitorId = monitor.data().get("monitor_id").asText();
ApiResponse<JsonNode> updated = blnk.balanceMonitor().updatePartial(
monitorId,
UpdateMonitorData.create()
.description("Below $250")
.condition(MonitorCondition.create().value(250))); // keeps field, operator, precision
// Core replies {"message": ..., "precision_unchanged": true} when a precision was
// sent without a value and it kept the stored one.Commit or void an inflight transaction idempotently with a reference (Core 0.15.7+),
and cap an overdraft with overdraftLimit (major units):
import com.blnkfinance.blnk.types.UpdateTransactionStatus;
String inflightId = "<transaction_id of an inflight transaction>";
blnk.transactions().updateStatus(
inflightId,
UpdateTransactionStatus.create().status("commit").reference("commit-" + inflightId));
blnk.transactions().create(
CreateTransactions.create()
.amount(50)
.precision(100)
.currency("USD")
.reference("ref_overdraft_001")
.description("Card spend")
.source(balanceId)
.destination("@CardSettlement")
.allowOverdraft(true)
.overdraftLimit(200)); // the source may go down to -$200List monitors for one balance (GET /balance-monitors/balances/:balance_id; Core
since ~0.14.x). The id is percent-encoded. list() still returns every monitor:
ApiResponse<JsonNode> monitorsForBalance =
blnk.balanceMonitor().listByBalanceId(balance.data().get("balance_id").asText());Pass your Blnk secret key as the first argument to Blnk.init. When set, every request
carries it in the X-Blnk-Key header; pass an empty string for unsecured self-hosted
instances.
For Cloud Proxy, pass a Cloud API key or OAuth access token as that first argument, set
baseUrl to https://api.cloud.blnkfinance.com/proxy, and set instanceId to the
target instance. Core request paths and bodies are unchanged.
Services are created lazily and cached per client instance:
ledgers(), ledgerBalances(), transactions(), balanceMonitor(),
reconciliation(), search(), identity(), system(), metadata(), hooks(),
apiKeys().
Request bodies are built with fluent builder types in com.blnkfinance.blnk.types;
fields you don't set are omitted from the JSON entirely. Date-typed fields accept
Instant, Date, or preformatted strings and are sent as UTC ISO-8601 timestamps
without fractional seconds (2026-12-31T23:59:59Z), the format Blnk Core expects.
| Option | Default | Notes |
|---|---|---|
baseUrl |
required | IllegalArgumentException if missing; / appended if absent. Use https://api.cloud.blnkfinance.com/proxy for Cloud Proxy |
instanceId |
unset | Cloud instance id (instance_...). When set, every request gets instance_id as a query parameter. Required for Proxy; omit for self-hosted Core |
timeout |
10000 ms |
per attempt; a timeout produces a synthetic 408 response and is never retried |
retryCount |
1 |
TOTAL attempts including the first; retries apply to GET requests only |
retryDelayMs |
2000 |
linear backoff: delay × attemptNumber |
logger |
console | any BlnkLogger; sensitive keys (API keys, tokens, cookies) are redacted from log metadata |
SDK methods never throw for request or validation failures — they return an
ApiResponse<T> value you can branch on:
status()— the HTTP status;400for client-side validation failures,408for timeouts,500for transport errors.message()—"Success", a specific validation message, or the error text. When Blnk Core returns a structurederror_detailbody, its message is used.data()— the parsed JSON body (nullon failure or empty body).error()— a structuredBlnkApiErrorDetail {code, message, details}when the Core returned a JSON error body.
Compare error().code() against the constants in BlnkErrorCodes, which mirror the
full Core 0.15.4 catalogue (TXN_ALREADY_REFUNDED, BAL_NOT_FOUND,
TXN_INSUFFICIENT_FUNDS, TXN_DUPLICATE_REFERENCE, LGR_NOT_FOUND, and so on):
import com.blnkfinance.blnk.types.BlnkErrorCodes;
ApiResponse<JsonNode> refund = blnk.transactions().refund(transactionId);
if (refund.error() != null
&& BlnkErrorCodes.TXN_ALREADY_REFUNDED.equals(refund.error().code())) {
// 409: already refunded, or this id is itself a refund — nothing to do
}Client-side validation runs before any request is sent: an invalid payload returns a
400 response immediately and the HTTP layer is never invoked. The only throwing paths
are programmer errors: constructing a client without a baseUrl
(IllegalArgumentException) and requesting an unregistered service
(IllegalStateException).
mvn test # offline unit tests (live suites skip unless BLNK_E2E=1)
BLNK_E2E=1 mvn test # also runs integration + e2e against http://localhost:5001Core0159IntegrationTest is also run in CI against a real ghcr.io/blnkfinance/blnk:0.15.9
(.github/workflows/integration-core.yml). To run it locally against another Core:
BLNK_E2E=1 BLNK_BASE_URL=http://localhost:5001 BLNK_API_KEY=<secret_key> \
mvn test -Dtest=Core0159IntegrationTestA Postman collection for the Core 0.15.3 flows is in
postman/blnk-java-core-0.15.3.postman_collection.json. Import it, set
baseUrl and apiKey, then run the collection.
Unit tests inject a mock transport and run fully offline. The live suites need a running
Blnk Core (docker compose up in the blnk repo).
src/main/java/com/blnkfinance/blnk/— client (Blnk,BlnkClientOptions),endpoints/(one class per service),types/(builder-pattern request DTOs and response records),validators/(client-side payload validation),util/(retry policy, log redaction, JSON and multipart helpers).src/test/java/— unit suites per endpoint/validator,testsupport/fixtures and mocks,integration/ande2e/live suites (environment-gated).