The REST bulk endpoint reduces request overhead when several independent operations target the same ledger.
Use one transaction with several postings when the movements form one accounting event. Use bulk when each element is an independent operation with its own identity and result.
Prerequisites#
You need an existing normal ledger, a token with the write scopes required by every element, and ledger:read for the account checks in this guide. With the default scope mapping, the virtual ledger:write scope covers all four: ledger:TransactionWrite for CREATE_TRANSACTION and REVERT_TRANSACTION, ledger:MetadataWrite for ADD_METADATA and DELETE_METADATA. Bulk checks the required scope per element.
These HTTP write examples assume that the cluster accepts unsigned requests. If your cluster requires Ed25519 request signatures, follow Configure Request and Response Signing and use a signed gRPC client or ledgerctl configured with a signing key; the HTTP write handlers submit unsigned requests.
If the ledger enforces account types, replace the demo addresses with values that match its configured patterns.
Give every element a distinct ik value. This is the per-operation idempotency key used by the normal sequential REST path.
REST surface#
This guide covers POST /v3/{ledgerName}/bulk with an application/json array. The ledger name in the path applies to every element, so one REST bulk request cannot span ledgers.
The REST endpoint accepts these actions:
action | data |
|---|---|
CREATE_TRANSACTION | The same postings, script, or scriptReference fields as a transaction create request. |
ADD_METADATA | targetType, targetId, and metadata for an account or transaction. |
REVERT_TRANSACTION | id plus optional force, atEffectiveDate, and metadata. |
DELETE_METADATA | targetType, targetId, and key for an account or transaction. |
Account-type bulk actions exist on the gRPC surface but are not accepted by this REST endpoint. Do not infer parity between the two transports.
A bulk result exposes only the created transaction for a CREATE_TRANSACTION element, and a successful non-create element omits data entirely. Post-commit volumes ride on that created transaction, and no request field adds volumes to any other element. Verify affected accounts with separate reads.
Observe the default stop behavior#
By default, Ledger processes elements in order and stops after the first failure; operations that completed before it remain committed. The second element below deliberately reuses the first element's transaction reference. The third element is valid but appears after the failure.
Submit the request without continueOnFailure:
Expected result:
- the first element has
responseType: "CREATE_TRANSACTION"and a non-zerologID; - the second has
responseType: "ERROR"anderrorCode: "TRANSACTION_REFERENCE_CONFLICT"; - the third has no committed log because processing stopped;
- the top-level status is a business
4xx, driven by the second element.
Verify the state rather than inferring it from the top-level status:
Both assertions return true. The first account has USD 10.00. Ledger returns an empty account view for an address with no volumes or metadata, so the empty volume list—not a 404 status—shows that the third operation did not run.
Continue after business failures#
Set continueOnFailure=true when independent later elements should still run after a per-element business 4xx:
The first element replays its original result through $BULK_PREFIX:1. The second replays its reference-conflict outcome through $BULK_PREFIX:2. The third now commits under $BULK_PREFIX:3.
continueOnFailure changes the top-level status and whether later elements run. It does not hide per-element errors. Inspect every item in .data, even when the HTTP response is 200.
Turn an expected conflict into a recorded skip#
Some import and replay workflows expect a specific business conflict. Add skippableReasons to that element to record a no-op instead of an error:
The skipped result contains this information; the concrete reference and transaction ID depend on the run:
A skipped element creates an auditable skip log but does not apply the attempted posting.
The REST whitelist is intentionally narrow:
| Action | Supported skippable reason |
|---|---|
CREATE_TRANSACTION | TRANSACTION_REFERENCE_CONFLICT |
REVERT_TRANSACTION | TRANSACTION_ALREADY_REVERTED |
DELETE_METADATA | METADATA_NOT_FOUND |
Ledger rejects reasons outside the action's whitelist when it processes that element. In sequential mode, earlier elements may already have committed; in atomic mode, the whole batch fails. ADD_METADATA has no REST skippable reason.
Make the whole batch atomic#
Set atomic=true when every element must commit or none may commit. Ledger sends the array as one atomic batch. Use one Idempotency-Key header for that batch; per-element ik values belong to sequential mode and do not identify an atomic request.
The example below deliberately repeats a reference inside a new atomic batch. The conflict rejects both elements:
Verify that neither account received funds:
Do not combine atomic=true with continueOnFailure=true: atomic execution has no successful prefix to continue after. If several postings describe one accounting event, a single transaction remains the clearer model; use atomic bulk for distinct operations that share one commit boundary.
Handle response classes#
Bulk failures fall into three groups:
| Response | Meaning | Client action |
|---|---|---|
Request-level 400, 401, 403, or 413 | Ledger rejected the request before processing elements | Correct the body, credentials, scopes, or configured batch-size limit. Do not assume any element result from a missing .data array. |
Per-element business 4xx | One operation failed validation, lookup, conflict, or a precondition | Inspect each item. In sequential mode, preceding items may have committed and later items did not run. In atomic mode, no element commits. |
429, 500, or 503 | A rate limit, service failure, stale input resolution, or unavailable Numscript preload occurred | continueOnFailure does not turn these into 200. Inspect errorCode, honor Retry-After when present, and retry only with bounded backoff. A repeated PRELOAD_UNAVAILABLE can indicate invalid Numscript input rather than an infrastructure outage. |
The maximum number of elements is a server setting. Ledger returns 413 with BULK_SIZE_EXCEEDED when the request exceeds that configured limit. Split work into bounded batches instead of assuming one fixed limit across environments.
Retry a bulk request#
For a sequential top-level 500 or 503, inspect every errorCode, then retry the same array after bounded backoff while the outcome is uncertain. Preserve every element's ik and original data. Elements that committed replay their outcomes; elements that did not run can proceed. Stop and validate the program and variables if Numscript PRELOAD_UNAVAILABLE persists.
For an atomic timeout or retryable service failure, resend the exact array with the same batch-level Idempotency-Key header. Do not add or change per-element keys. No successful prefix can escape a failed atomic batch, but the stable batch key protects a commit whose response was lost.
For a completed response with business errors:
- persist the result for every element;
- treat a successful or explicitly skipped item as complete;
- diagnose each failed item by
errorCode; - create a corrected operation with a new
ikonly when its logical content changes; - verify balances, metadata, or reversion state independently.
Do not generate fresh keys for an unchanged whole-batch retry. That can duplicate the elements that committed before the failure.
Continue with Write Transactions to choose between a single transaction, a saved Numscript program, and a bulk request.