employee-name, that you set in the sajn editor. Your code fills in values by key, so it keeps working when someone edits the text around the fields.
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). - Create a template in the sajn app with FORM fields that have keys, and with the parties the document needs, such as
Employee. To find the template’s ID, call List all templates withqueryset to part of its name.
Create, fill in, and send
1
Create the document from the template
Send a Replace
POST request to /api/v1/documents with the templateId. Leave out parties, so the document keeps the template’s parties and the signature boxes placed for them:TEMPLATE_ID with the template’s ID. The response is the document, with a copy of each template party in parties. The document also gets the template’s settings, such as the signing mode and the reminders.If you send parties in this request, they replace the template’s parties, and signature and initials boxes placed on a PDF for the template’s parties are removed. Use that only for templates without placed boxes.2
Find the keys
List the values you can fill in:Replace The keys are the same for every document from the template, so you can look them up once.
DOCUMENT_ID with the document id. The response lists the values in data. Each value has a key, a label, a type, and filledBy. You can write values where filledBy is SENDER. A party fills in the values where filledBy is SIGNER:3
Fill in the values
Send every value in one The response reports each key in The example leaves out the
PATCH request:results, lists required values that are still empty in remaining, and returns every value in data:data list. Check each result’s success. A value fails, and the others are still written, when its key doesn’t exist, two fields share the key, a party fills it in, or it doesn’t match the type or the options. Send at most 100 values per request. A FORM CHECKBOX value is a list of the selected options, such as ["Remote", "Parking"].4
Put the right people in the parties
Update each copied party with the real person. Properties you leave out stay unchanged:Replace
PARTY_ID with the id of the copied party, such as the one named Employee. To add a party the template doesn’t have, send a POST request to /api/v1/documents/DOCUMENT_ID/parties with a contactId.5
Send the document
PENDING. For the response codes and the invitation message, see Send a document for signing.Change other properties of FORM subfields
Thefield-values endpoint writes values only. To change other properties of a FORM subfield, such as its label or the party who fills it in, update the FORM field that holds it.
- Find the field with
GET /api/v1/documents/DOCUMENT_ID/fields?key=start-date. The response lists the FORM field indata, with every subfield infieldMeta.fields. - Change the subfield in that
fieldMeta, and send the wholefieldMetain aPATCHrequest to/api/v1/documents/DOCUMENT_ID/fields/FIELD_ID. The update replaces the field’sfieldMeta, so a subfield you leave out is removed.
FIELD_ID with the id of the FORM field. The response is the updated field.
Handle errors
results[].success: falsefromfield-values: readerror.codeanderror.message. The other values are written.409 INVALID_STATE: the document isn’t aDRAFT, because you can fill in values only before sending. Fromfield-values, it can also mean that another edit changed one of the fields while the request ran, and nothing was written. Send the request again.404 NOT_FOUND: the template or the document doesn’t exist in the workspace that the API key belongs to.
Next steps
Bulk-create from a template
Create one document per row of your data.
Manage templates
Create and change templates through the API.
Fields that parties fill in
Leave inputs for the party to complete.
Fill in values on a document
See the endpoint in the API reference.

