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 thedocument.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
1
Set the redirect URL on the document
Set Replace
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: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:2
Handle 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: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.
Next steps
Embedded signing
Show the signing page inside your application.
Webhooks
Confirm signatures server to server.

