Skip to main content

Java SDK

dev.formfeed:formfeed is the Java client for the REST API, for Java 11 and later. It behaves exactly like the TypeScript SDK: 429, 503 and network errors are retried, every render carries an Idempotency-Key, and API problems throw FormfeedException, an unchecked exception. It sends with the JDK's own java.net.http.HttpClient and needs nothing but Jackson databind 2.x, which it brings along and which a Spring application has already.

Maven:

<dependency>
<groupId>dev.formfeed</groupId>
<artifactId>formfeed</artifactId>
<version>0.3.35</version>
</dependency>

Gradle:

implementation("dev.formfeed:formfeed:0.3.35")

Set up a client​

import dev.formfeed.Formfeed;

Formfeed formfeed = Formfeed.builder().apiKey(System.getenv("FORMFEED_API_KEY")).build();
Builder methodDefaultNotes
apiKey(String)requiredff_live_… or ff_test_…
region(String)"eu""eu" (https://api-eu.formfeed.dev/v1) or "us" (https://api-us.formfeed.dev/v1)
baseUrl(String)region hostFull URL including /v1, used instead of the region's host. You need it only for an address other than the public API, such as one our support gives you. Wins over region.
httpClient(HttpClient)the SDK'sA java.net.http.HttpClient with your own proxy, executor or TLS settings. The SDK's own follows redirects and gives up connecting after ten seconds.
maxRetries(int)3Retries on 429, 503 and network errors; 0 turns retrying off.
timeout(Duration)120 secondsHow long each request may take until its answer arrives, with your HttpClient too. A request that times out counts as a network error and is retried.
header(String, String)noneSent with every request, after the SDK's own headers, so it can replace one of them.
objectMapper(ObjectMapper)a plain oneThe Jackson 2 mapper that writes requests and reads answers. Pass your application's, so the objects in your data keep its modules (for dates, say).
sleeper(Sleeper)sleepsHow the client waits between retries and polls; for tests.
jitter(DoubleSupplier)randomWhich share of the 250 ms of jitter a retry adds, from 0 to 1; for tests.

build() throws FormfeedException with the code invalid_request without an API key or with a region that is neither eu nor us. One client serves any number of threads, so make one and share it, as a Spring bean for example. A render's request is a RenderRequest or a map, every other request a map with the fields of the API reference, and an answer is an immutable model with getters (a render, a job, a page, a file, a template, usage, PDF info, a webhook endpoint) or else a read-only map: render.getDownloadUrl(), render.getPageCount(), render.getUnits(), and render.getRaw() with the whole answer, fields of later API versions included. Values such as a status stay plain strings, so a value the API adds later never breaks a read.

Retries and idempotency​

The rule is the one of the TypeScript SDK: 429, 503 and network errors are sent again up to maxRetries times, after the seconds of Retry-After, else 0.5 s, 1 s, 2 s and so on plus up to 0.25 s of jitter, never more than 30 s. renders().create, renders().batch, every PDF tool but info, and einvoices().validate send an Idempotency-Key, a random one unless you pass one as the last argument; its retries reuse it, so the API renders and charges once. To retry safely across processes, pass a key of your own, such as order-8812-invoice. See Idempotency.

Render​

import dev.formfeed.Render;
import dev.formfeed.RenderRequest;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

Map<String, Object> invoice = Map.of(
"number", "2026-0042",
"lines", List.of(Map.of("description", "Consulting", "qty", 8, "price", 120)));

Render render = formfeed.renders().create(
RenderRequest.template("invoice")
.data(Map.of("invoice", invoice))
.filename("invoice-" + invoice.get("number") + ".pdf"),
"order-8812-invoice");

// a sync render still running after 60 seconds comes back queued; wait for it
if (!"succeeded".equals(render.getStatus())) {
render = formfeed.renders().waitFor(render);
}
System.out.println(render.getDownloadUrl() + " " + render.getPageCount() + " " + render.getUnits());

formfeed.renders().downloadTo(render, Path.of("invoice.pdf"));

A RenderRequest starts from its source: RenderRequest.template(slug), html(html) (with engine(…) for a template language), url(url) or markdown(text). Its setters name the fields most renders use: data, version, output, engine, settings, filename, expiresIn, mode, locale, webhookUrl and webhookSecret, meta, validateData and post; set("access", "public") sends any other field of POST /renders (access, region, dedupe, canary_key, storage) as the API names it. data takes a map, a Jackson tree or any object Jackson writes as a JSON object, such as a class of your own domain. renders().create() also takes the whole request as a map. The second argument, the idempotency key, is the SDK's own.

A failed render throws FormfeedException. A sync render that has no answer after 60 seconds is not an error: it comes back with the status queued or rendering and finishes in the background (the automatic fallback), so check getStatus() before you download. renders().get(id) fetches a render again, with a fresh download link. download(render) returns the file's bytes, downloadTo(render, path) streams them into the file, which it replaces only once the download is complete, and answers the number of bytes; both throw not_ready while the render has no output.

Async renders and batches​

import dev.formfeed.Job;
import java.time.Duration;
import java.util.ArrayList;

Render queued = formfeed.renders().create(
RenderRequest.template("annual-report").data(payload).mode("async"));
Render done = formfeed.renders().waitFor(queued, Duration.ofMinutes(2), Duration.ofSeconds(1));

List<Map<String, Object>> items = new ArrayList<>();
for (Map<String, Object> order : orders) {
items.add(Map.of(
"data", Map.of("invoice", order),
"filename", order.get("number") + ".pdf",
"meta", Map.of("order_id", order.get("id"))));
}
Job job = formfeed.renders().batch(Map.of("template", "invoice", "zip", true, "items", items));
Job finished = formfeed.jobs().waitFor(job);
System.out.println(finished.getStatus() + " " + finished.getSucceeded() + " " + finished.getFailed() + " " + finished.getZipUrl());

renders().waitFor(render, timeout, interval) asks every interval until the render succeeded or failed and returns it either way; after timeout it throws FormfeedException with the code timeout, while the render goes on. Without the two it asks every second for at most two minutes. jobs().waitFor(job) does the same for a batch, every two seconds for at most ten minutes unless you pass the two, and returns once the job is completed, partially_failed or failed; job.getItems() are its renders in the order of the request. For anything that takes more than a few seconds in production, prefer webhooks over polling.

List renders and delete outputs​

import dev.formfeed.Page;
import dev.formfeed.RenderInput;

Page<Render> page = formfeed.renders().list(Map.of("template", "invoice", "status", "failed", "limit", 20));
for (Render failed : page.getData()) {
System.out.println(failed.getId() + " " + failed.getError().get("code"));
}

// an Iterable that follows the cursor, a page at a time
for (Render each : formfeed.renders().all(Map.of("since", "2026-08-01T00:00:00Z", "until", "2026-09-01T00:00:00Z"))) {
// …
}

formfeed.renders().deleteOutputs(render); // needs the file:delete scope

RenderInput kept = formfeed.renders().input(render); // the kept request (render:input); 410 render_input_expired when not kept

PDF tools​

import dev.formfeed.PdfInfo;
import dev.formfeed.Upload;

// in the same render: steps run as merge, watermark, password
Render contract = formfeed.renders().create(
RenderRequest.template("contract").data(data).post(Map.of("watermark", Map.of("text", "DRAFT"))));

// on renders you already have (a Render or its id) and library files; each answers a new render
Render bundle = formfeed.pdf().merge(List.of(contract, "terms.pdf"), Map.of("filename", "bundle.pdf"));
Render locked = formfeed.pdf().protect(bundle, Map.of("user_password", "open-sesame", "permissions", List.of("print")));
PdfInfo info = formfeed.pdf().info(locked); // getPageCount(), getPages(), isEncrypted(), getMetadata(), getForm(); free

// office documents to PDF: an upload (Word, Excel, PowerPoint, OpenDocument, RTF or HTML, up to 20 MB, not kept)…
Render report = formfeed.pdf().convert(
Upload.fromPath(Path.of("report.xlsx")), Map.of("single_page_sheets", true, "filename", "report.pdf"));
// …or the output of a Word or PowerPoint template render
Render offerPdf = formfeed.pdf().convert(offerRender, Map.of("page_ranges", "1-3"));

// split, compress, draw, redact and fill: a stored PDF, or an Upload that is never kept
Render parts = formfeed.pdf().split(bundle, Map.of("ranges", List.of("1", "2-"))); // output zip
Render thumbnail = formfeed.pdf().toImage(bundle, Map.of("pages", "1", "dpi", 72)); // output png
Render redacted = formfeed.pdf().redact(
Upload.fromPath(Path.of("invoice.pdf")), Map.of("text", List.of("Max Mustermann")));
Map<String, Object> form = formfeed.pdf().info("antrag.pdf").getForm(); // every field's name, type, value and options
Render filled = formfeed.pdf().fill(
"antrag.pdf", Map.of("fields", Map.of("customer.name", "Erika Mustermann"), "flatten", true));

Starter plan and higher, 0.5 units per step on live keys; a conversion is counted like a PDF render, toImage one unit per picture. info is free on every plan. A source is a Render or its id, or a LibraryFile or its id or name. info, split, compress, toImage, redact and fill also take an Upload (Upload.fromPath(path), Upload.fromPath(path, name) or Upload.fromBytes(bytes, name)), which is sent as multipart and never kept, and convert takes an Upload or the render of a Word or PowerPoint template; merge, protect and watermark work on stored PDFs only and throw IllegalArgumentException for an upload. The options are maps with the fields of each tool as the PDF tools page describes them, output options included (filename, expires_in, access, meta, storage). A result of several files is one ZIP (getOutput() is "zip"). redact draws a black box over what it removed, and none with fill set to null, which takes a HashMap, since Map.of refuses a null. fill puts what it did in the render's getForm().

E-invoice validation​

// an e-invoice this workspace rendered: answered from the report the render keeps, free
Map<String, Object> report = formfeed.einvoices().validate(render);

// an XML Formfeed did not make (up to 4 MB, from the Starter plan): one of the day's validations
Map<String, Object> received = formfeed.einvoices().validate(
Upload.fromPath(Path.of("RE-2026-0001.xml")), "xrechnung");

validate says which rules an e-invoice passed, by which validator and release, and which bytes it judged; the answer is the report as a map, in the shape E-invoice validation describes. A render goes as JSON with its id, an Upload as multipart. The second argument names the rules: auto, the default, takes the rule set the file's specification identifier names, and for a render answers from its stored report; factur-x, xrechnung and en16931 hold the file to that set. It needs the einvoice:validate scope, and a library file is refused with IllegalArgumentException, since an e-invoice is validated from a render or an upload.

File library​

import dev.formfeed.LibraryFile;

// the same name replaces the file everywhere; templates use {{ asset('brand/logo.png') }}
LibraryFile logo = formfeed.files().upload(Upload.fromPath(Path.of("logo.png"), "brand/logo.png"));
System.out.println(logo.getUrl());

for (LibraryFile file : formfeed.files().all(Map.of("prefix", "brand/"))) {
System.out.println(file.getName() + " " + file.getBytes());
}
formfeed.files().delete(logo);

// library files in post-processing: an image watermark and a PDF merged by name
formfeed.renders().create(RenderRequest.template("contract").data(data)
.post(Map.of("watermark", Map.of("image", "draft.png"), "merge_after", List.of("terms.pdf"))));

upload sends the Upload's name as the library name, so it has to be a valid one. file:read, file:write and file:delete scopes. Library files are served without a signature; see Files.

Templates​

import dev.formfeed.Template;

for (Template template : formfeed.templates().all(Map.of("kind", "pdf"))) {
System.out.println(template.getSlug() + " " + template.getPublishedVersion());
}

Map<String, Object> schema = formfeed.templates().schema("invoice"); // JSON Schema of the expected data
Map<String, Object> check = formfeed.templates().validate("invoice", Map.of("data", data)); // ok, template, diagnostics; renders nothing

templates().get(slug) reads one template; schema(slug, version) takes "published" (the default), "latest", a version number or a channel name, and returns the stored data schema, else one inferred from the sample data. The Java SDK reads and checks templates. Writing versions, publishing, release channels, the brand kit and shared partials have no methods yet; request reaches them.

Webhooks​

In Spring Boot, take the body as byte[], so it arrives untouched:

import dev.formfeed.Render;
import dev.formfeed.Webhook;
import dev.formfeed.WebhookEvent;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
class FormfeedWebhookController {
private final String secret = System.getenv("FORMFEED_WEBHOOK_SECRET");

@PostMapping("/webhooks/formfeed")
ResponseEntity<Void> receive(
@RequestHeader(name = "Webhook-Signature", required = false) String signature,
@RequestBody byte[] body) {
WebhookEvent event;
try {
event = Webhook.parse(secret, signature, body);
} catch (IllegalArgumentException e) {
return ResponseEntity.status(401).build();
}
if (event.getType().equals("render.completed")) {
Render render = Render.fromMap(event.getData());
// render.getId(), render.getDownloadUrl(), render.getMeta(): mark the order as invoiced, …
}
return ResponseEntity.noContent().build();
}
}

Pass the raw request body, as bytes or as the text it was, not JSON written again: the signature covers the bytes on the wire, and a body that went through an ObjectMapper and back no longer matches. parse returns the event (getId(), getType(), getCreatedAt(), getWorkspaceId(), getData()) and throws IllegalArgumentException when the signature does not match or its timestamp is more than five minutes from the current time; a variant with two more arguments takes a tolerance and a clock of your own. Webhook.verify(secret, header, rawBody) returns a boolean instead of throwing. Render.fromMap(event.getData()) reads a render event's data, Job.fromMap a job event's. Any answer but 2xx is retried, so the 401 above means a delivery that failed the check is sent again later. Endpoints are managed with formfeed.webhooks().create(Map.of("url", …, "events", List.of(…))), list(), update(id, patch), delete(id) and test(id); create and update take environments. formfeed.webhooks().resend(eventId, endpointId) sends a stored event again. A complete receiver without Spring is in the Java guide; see Webhooks for the scheme.

Usage and account​

import dev.formfeed.Usage;

Usage usage = formfeed.account().usage(); // current period
Usage august = formfeed.account().usage("2026-08"); // the period that started in August 2026
System.out.println(usage.getUsed() + " of " + usage.getIncluded());

Map<String, Object> account = formfeed.account().get(); // workspace, organisation, plan, limits

Units are counted per organisation, in billing periods that renew on the day the subscription started (calendar months on the Free plan without a subscription). Both need account:read.

Errors​

import dev.formfeed.FormfeedException;

try {
formfeed.renders().create(RenderRequest.template("missing"));
} catch (FormfeedException e) {
System.out.println(e.getCode() + " " + e.getStatus() + " " + e.getRequestId()); // template_not_found 404 req_…
System.out.println(e.getProblem().getRaw()); // the full problem body
}

e.getCode() is the problem code of the API's answer, e.getMessage() its detail and e.getStatus() its HTTP status; e.getProblem() is the problem body (getType(), getTitle(), getDetail(), getErrors(), getRaw() with every member), null when the answer had none, and e.getRequestId() the X-Request-Id to quote to support. FormfeedException is unchecked, so catch it where you can tell the user something useful. Failures on the client's side have the status 0, unless the table says otherwise, and these codes:

CodeWhen
network_errorThe request could not be sent or timed out on every attempt
timeoutrenders().waitFor or jobs().waitFor ran out of time; the render or job goes on
not_readyrenders().download or downloadTo of a render that has no output yet, or failed
download_failedThe download link answered an error (the status is the link's)
invalid_responseThe API answered with a body that is not the JSON the call expects (with the answer's status when the body is not JSON at all)
invalid_requestThe client was built without an API key, or with a region that is neither eu nor us
interruptedThe thread was interrupted while the call waited; its interrupt flag is set again

An error answer without a problem code gets http_<status>, such as http_502. Webhook.parse throws IllegalArgumentException, not FormfeedException.

Any other call​

Object channels = formfeed.request("GET", "/templates/invoice/channels");

request(method, path), request(method, path, body) and request(method, path, body, idempotencyKey) reach any call of the API with the client's key, retries and errors. The path is the part after /v1, the body is sent as JSON (a map, a list or any object Jackson writes), and the answer comes back decoded as read-only maps, lists, strings, numbers and booleans, null for an answer without a body.