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 document to set values on. For more information, see Create a document.
How custom fields work
A custom field definition has the following properties:name: the name shown in the sajn app, such asProject code.type: what the field belongs to.DOCUMENTfields hold values on documents, andCONTACTfields hold values on contacts.inputType: the kind of value:TEXT,TEXTAREA,NUMBER,DATE,EMAIL,PHONE,URL,BOOLEAN,SELECT, orJSON.required: whether the field needs a value.options: forSELECT, the choices as an array of strings, such as["HR", "Sales"].defaultValue: optional.
"50000", a date as "2026-12-31", and a boolean as "true" or "false".
The API sets values on documents. CONTACT field values are set in the sajn app.
Define a field and set its value
1
Create the definition
Send a The response is the definition:Definitions are shared by the workspace. To find existing ones, call List all custom fields, optionally with
POST request to /api/v1/custom-fields:type=DOCUMENT. The list is in data; while hasMore is true, pass nextCursor as cursor to get the next page.2
Set the value on a document
Send Replace
customFields with the definition’s id as customFieldId. You can send it when you create the document, or with a PATCH request:DOCUMENT_ID with the document ID. To clear a value, send "value": null.3
Read the values
Get the document. Its The following example shows only
customFields array has every value, with the field’s name and inputType as type:customFields:Use the values
- In the invitation message:
{{custom.department}}inserts the value of the field namedDepartment. The slug is the field name in lowercase with hyphens. For more information, see Send a document for signing. - To show or hide content: a
TEXTorHTMLfield can have avisibilityRulewith acustomFieldId, a value inequals, and amodeofSHOW_WHENorHIDE_WHEN. - By document type: a document category (Dokumenttyp) scopes which custom fields apply to its documents. Set
documentMeta.documentCategoryId, and call List document categories to see each category’scustomFieldIds. - From a CRM: send
integrationLinkwhen you create a document, and sajn prefills mapped custom fields from the linked record. For more information, see CRM field integration.
Change or delete a definition
To rename a field or change its options, send aPATCH request to /api/v1/custom-fields/CUSTOM_FIELD_ID. Every property is optional, and type can’t change. Changing inputType can make existing values invalid for the new type.
To delete a field, send a DELETE request to the same path. The response is { "id": "CUSTOM_FIELD_ID", "deleted": true }. Deleting a definition removes its values from every document and contact. To keep a copy of the definition, get it before you delete it.
Handle errors
400 VALIDATION_FAILED:name,type,inputType, orrequiredis missing or unknown, oroptionsis a JSON-encoded string instead of an array.404 NOT_FOUND: no custom field has the ID.
Next steps
Organize with tags
Group documents without structured values.
CRM field integration
Prefill custom fields from a CRM record.
Create a custom field
See the endpoint in the API reference.

