A complete Spring Boot app that sends a contract for signature, lets the user sign it inside your page (embedded ceremony), and tracks the result with verified webhooks.
Most e-signature integrations need three things working together: a server call that creates the envelope, a signing experience that keeps users in your product, and a reliable way to learn when signing is done. Getting any one wrong leaks your API key, breaks the iframe, or trusts forged webhook calls.
A small Spring Boot app. The API client uses only the JDK (java.net.http); Jackson, which Spring Boot already ships, parses JSON.
| Route | Purpose |
|---|---|
GET / |
A page with a form and the ceremony iframe |
POST /api/contracts |
Creates the envelope on the server and returns the ceremony URL |
GET /api/contracts/{id} |
Confirms the envelope status on the server |
GET /api/contracts/{id}/signed.pdf |
Streams the signed PDF (the deliverable) through your server |
POST /webhooks/signatureapi |
Receives events, verifies the signature on the raw body, dedupes retries |
ContractController.java holds the routes. SignatureApi.java holds the API client and the envelope builder. WebhookVerifier.java holds the Standard Webhooks verifier. The page is src/main/resources/static/index.html.
- JDK 21. The Maven wrapper (
./mvnw) downloads Maven for you. - A SignatureAPI test API key (
key_test_...). Sign up for free. - For webhooks on your machine: a webhook endpoint in the dashboard pointing at a public tunnel, or
npx signatureapi listenfrom the SignatureAPI CLI, which forwards test events and saves the signing secret.
The browser never sees your API key. POST /api/contracts calls SignatureApi.buildContract(), which sets three recipient options for embedding:
"recipients": [{
"key": "client", "type": "signer", "name": "...", "email": "...",
"delivery_type": "none",
"ceremony": {
"authentication": [{ "type": "custom", "provider": "Acme Corp Portal", "data": { "user_id": "usr_..." } }],
"embeddable_in": ["http://localhost:8080"]
}
}]delivery_type: none means no emails: your app shows the result. embeddable_in is the origin allowed to frame the ceremony. custom authentication records that your app already signed the user in, so the ceremony URL comes back in the response at recipients[0].ceremony.url.
The envelope starts in processing, and the ceremony opens only once it is in_progress. createSigningSession() reads the envelope once a second until then and returns the ceremony URL from that read.
src/main/resources/static/index.html adds the two required query parameters and loads the URL in an iframe:
src.searchParams.set('embedded', 'true');
src.searchParams.set('event_delivery', 'message');It accepts message events only when event.origin is https://sign.signatureapi.com and event.source is the iframe. A ceremony.completed message is a UI signal, so the page then asks your server for the real status.
SignatureAPI signs each delivery with the Standard Webhooks scheme. WebhookVerifier.verify() computes an HMAC-SHA256 over webhook-id.webhook-timestamp.body with your signing secret, compares in constant time, and rejects timestamps older than 5 minutes. It runs on @RequestBody byte[] rawBody, the exact bytes received: binding a DTO parses the JSON first, and re-serializing it changes the bytes and breaks the signature.
Deliveries retry for up to 48 hours and can arrive out of order. The handler remembers each webhook-id and answers duplicates with 200 without processing them again. In production, store the ids in your database with a unique index.
When the envelope completes, SignatureAPI generates the deliverable: the signed PDF with its audit log. downloadSignedPdf() reads the envelope, gets its deliverable, and downloads the file from the deliverable's url. That URL is pre-signed and expires after 1 hour, so the app requests a fresh one on each download instead of storing it. Until the deliverable is generated, the route answers 409 and the page can try again a few seconds later.
export SIGNATUREAPI_KEY=key_test_YOUR_KEY
export SIGNATUREAPI_WEBHOOK_SECRET=whsec_... # from the webhook endpoint in the dashboard
export APP_ORIGIN=http://localhost:8080
./mvnw spring-boot:runOpen http://localhost:8080, keep the sample name and email, and select Start signing.
Tomcat started on port 8080 (http) with context path '/'
webhook envelope.completed for envelope eb4cf433-a8af-4161-b37b-7ef57d423e56
After signing, the page shows Thanks! Envelope status: completed, and the Download the signed PDF link saves signed-service-agreement.pdf.
./mvnw testThe tests run the shared webhook test vector through the app, then drive the controller with MockMvc against a local mock API (a JDK HttpServer) and check the envelope payload, the 422 path, webhook acceptance, tamper rejection, duplicate handling and the signed PDF download. With SIGNATUREAPI_KEY set, live tests create a real embedded-ceremony envelope in test mode and download the signed PDF of an envelope that an automatic signer completes.
- The iframe is blank or refuses to load:
embeddable_inmust match your page's origin exactly (scheme, host and port), and the URL needsembedded=true. - No
messageevents arrive: addevent_delivery=messageto the URL, and check that your origin filter useshttps://sign.signatureapi.com. - Every webhook returns 400
No matching signature: wrong secret (each endpoint has its own), or a proxy or body parser changed the body before verification. Timestamp outside the tolerance window: your server clock is off. Sync it with NTP.- The signed PDF route answers 409: the envelope is not completed yet, or the deliverable is still being generated. Try again in a few seconds.
ceremonyUrlis empty: the recipient is not usingcustomauthentication. Withemail_link, SignatureAPI emails the link instead.- The app stops at startup with
Set SIGNATUREAPI_KEY to a test API key: the key is missing or does not start withkey_test_.