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). - Read Fields that parties fill in for the FORM field format. Template fields use the same format as document fields.
Build a template
1
Create the template with its content
Send a The response is the template:Every template endpoint returns the template in this shape.
POST request to /api/v1/templates with a name and the fields in initialFields:fields is null unless you get the template with expand=fields. Store the template id. The subfield keys, employee-name and start-date, are the keys your code fills in on every document created from the template.2
Add the default parties
Add a placeholder party for each person who signs. A template party has a Replace
name, a role, and its signing settings. Documents created from the template get a copy of each party, which you then update with the real person:TEMPLATE_ID with the template id. For a party who’s the same on every document, such as your HR manager, send contactId instead of name.For a party who signs for a company, send company with name and orgNumber, and optionally role, such as { "name": "Example AB", "orgNumber": "5566778899", "role": "CEO" }. Template parties and document parties nest the company the same way, and company is null for a private individual.3
Set the defaults for new documents
templateMeta holds the settings that every document created from the template starts with:templateMeta takes the same settings as documentMeta on a document, plus visibility and selectedUserIds, which control who can see documents created from the template. For every property, see Update a template.4
Tag the template
Add a tag that has Replace
TEMPLATE in its availableFor list:TAG_ID with the tag’s ID. For more information, see Organize documents with tags.5
Create a document from it
The template is ready. To create a document, fill in its values, and send it, see Create documents from templates.
Find, copy, and delete templates
- List templates with
GET /api/v1/templates. Filter by name withquery, and by tag withtagId. The response has the templates indata; to get the next page, passnextCursorascursorwhilehasMoreistrue. For more information, see Pagination. - Get one template with its
partiesandtagswithGET /api/v1/templates/TEMPLATE_ID. To include its content blocks infields, addexpand=fields. - Copy a template with all its fields and parties with
POST /api/v1/templates/TEMPLATE_ID/duplicate. Use a copy to change a template without affecting the original. - Delete a template with
DELETE /api/v1/templates/TEMPLATE_ID. The template moves to the trash, and the response is the template withdeletedAtset. sajn deletes it permanently after 90 days. Documents created from it aren’t affected. - List the documents created from a template with
GET /api/v1/documents?templateId=TEMPLATE_ID.
Change fields and parties
The template field and party endpoints work like their document counterparts:
A field update replaces the field’s
fieldMeta, so send the whole object. To change one FORM subfield, find its field by key, then send the field’s whole fieldMeta with the subfield changed. A field DELETE returns { "id": "FIELD_ID", "deleted": true }; to keep the content, read the field first. For the field formats, see HTML fields, Fields that parties fill in, and Place fields on a PDF.
Handle errors
400 VALIDATION_FAILED: a field or a party is invalid. For example, a role ofACCEPTORfails; sendSIGNER. Readissuesfor the path.409 INVALID_STATE: the template is locked against edits.404 NOT_FOUND: the template, the field, or the party doesn’t exist in the workspace.
Next steps
Create documents from templates
Fill in a template’s fields and send the document.
Templates and forms
Learn how templates and public forms relate.
Create a new template
See the template endpoints in the API reference.

