Redirect after signing
Send a party back to your application after they sign, with the document and party IDs in the URL
In this guide, you configure a document so that each party lands on a page in your application after signing. The URL can carry the document ID and the party ID, so your page knows who signed.
Before you begin
- Store your API key in the
SAJN_API_KEYenvironment variable. To create a key, go to workspace settings in the sajn app, then Utvecklare (Developer) > API-nycklar (API keys). - Have a page in your application that can receive the redirect, such as
https://app.example.com/signed.
How the redirect works
When a party finishes signing, the signing page counts down for five seconds and then opens the redirect URL in the same tab. The party can cancel the countdown. The redirect happens in the party's browser, so it isn't proof that the document was signed. To confirm a signature, use the document.party.signed and document.completed webhook events.
The URL can contain the following placeholders. sajn replaces the first occurrence of each:
{documentId}: the document ID.{signerId}: the ID of the party who signed, the same value asidin the document'sparties. The placeholder keeps this name in every API version.
Configure the redirect
Set the redirect URL on the document
Set documentMeta.redirectEnabled to true and documentMeta.redirectUrl to an http or https URL. You can send them when you create the document, or update a document you already have:
curl -X PATCH https://app.sajn.se/api/v1/documents/DOCUMENT_ID \
-H "Authorization: Bearer $SAJN_API_KEY" \
-H "Sajn-Version: 2026-10" \
-H "Content-Type: application/json" \
-d '{
"documentMeta": {
"redirectEnabled": true,
"redirectUrl": "https://app.example.com/signed?doc={documentId}&party={signerId}"
}
}'Replace DOCUMENT_ID with the document ID. The response is the document, with the URL in documentMeta.redirectUrl. You can change the redirect after sending, until the document is completed.
After Alex signs, the browser opens a URL similar to the following:
https://app.example.com/signed?doc=cm4k2x9p10001abcd1234efgh&party=cm4k2xa3f0002abcd5678ijklHandle the redirect in your application
On the redirect page, read the IDs from the query string. To show the current state, get the document from your server, never from the browser, because the request needs your API key:
// Express route on your server.
app.get("/signed", async (req, res) => {
const { doc, party } = req.query;
const response = await fetch(`https://app.sajn.se/api/v1/documents/${doc}`, {
headers: {
Authorization: `Bearer ${process.env.SAJN_API_KEY}`,
"Sajn-Version": "2026-10",
},
});
const document = await response.json();
const signedParty = document.parties.find((p) => p.id === party);
res.render("signed", { documentName: document.name, signed: signedParty?.signingStatus === "SIGNED" });
});Treat the query string as untrusted input. Anyone can open the URL with other IDs, so check that the document belongs to the signed-in user before you show it.
Handle errors
400 VALIDATION_FAILED:redirectUrlisn't anhttporhttpsURL.409 INVALID_STATEafter sending: the document is completed, cancelled, or rejected, and the redirect can no longer change.
For the error shape and every code, see Errors.
Next steps
Was this page helpful?
Last updated on