Skip to Content
Document content

Create document content

POST
/api/v1/documents/{id}/content

Adds content blocks to a document. Send the blocks in content, even when you create one.

Field Types:

  • TEXT - Rich text content section (Tiptap editor format)
  • HTML - Raw HTML content with custom styling (API-only, sanitized for security)
  • FORM - Form with input fields for signers
  • PDF - PDF file section
  • PRODUCT_TABLE - Product/service table with pricing
  • TABLE - Simple table with custom rows and columns
  • SPACER, PAGE_BREAK, DURATION - Layout and duration blocks

Field Position: The 0-based index of the field among the content blocks. A field sent to a taken index goes there, and the fields from that index on move down by one. A position past the end puts the field last.

Field Metadata: Each field type has specific metadata requirements. See schema documentation for details.

Placing fields on a PDF: a PDF field renders an uploaded PDF (fieldMeta.value is the storage key returned by the files endpoint). Add boxes on its pages with fieldMeta.placedFields. Each entry has a unique id, a page counted from 1, a rect (x, y, width, height), and a kind. By default, rect is in fractions of the page from 0 to 1, measured from its top-left corner, so { "x": 0.1, "y": 0.8, "width": 0.3, "height": 0.05 } is a box near the bottom left. To send PDF points from the bottom-left corner instead, set unit to POINTS and origin to BOTTOM_LEFT. The server fills pageWidth, pageHeight, and pageRotation from the PDF page when you omit them, and responses always return relative values from the top-left corner. The box kinds are the following:

  • INPUT with inputType SIGNATURE or INITIALS and a partyId: a mark the party draws at signing, sealed into the PDF at that position.
  • INPUT with inputType TEXT, DATE, CHECKBOX or SELECT and a partyId: a value the party fills in before signing. Set required to block signing until it is filled.
  • STATIC with content (HTML): fixed text stamped at that position.

Set key on an INPUT box to fill it in by that key through PATCH /api/v1/documents/{id}/field-values. A key can contain lowercase letters, digits, hyphens, and underscores.

The following example creates a PDF field with a signature box:

{  "content": [    {      "type": "PDF",      "position": 0,      "fieldMeta": {        "type": "PDF",        "value": "f/org_123/abc123def/contract.pdf",        "placedFields": [          {            "id": "sig-1",            "kind": "INPUT",            "inputType": "SIGNATURE",            "page": 2,            "rect": { "x": 0.12, "y": 0.83, "width": 0.34, "height": 0.06 },            "partyId": "PARTY_ID",            "required": true          }        ]      }    }  ]}

The request fails with an HTTP 400 Bad Request status code, and writes nothing, when a box has a page the PDF doesn't have, doesn't fit on its page, names a partyId that isn't a party on the document, or is a SIGNATURE or INITIALS box without a party with the SIGNER role. The issues array in the response lists every problem with its path, such as content.0.fieldMeta.placedFields.2.rect.

The response lists the created fields in request order, each in the same shape as GET /api/v1/documents/{id}/content/{contentId}. To add, move, or remove single boxes later, use PATCH /api/v1/documents/{id}/content/{contentId}/placed-fields.

Product tables: a PRODUCT_TABLE field's price values are decimal amounts in the table's currency, such as 1499.5, not minor units. vat is a rate in percent, such as 25.

Fields a party fills in: In TEXT or HTML content, place a field with a <sajn-field> tag, such as <sajn-field key="buyer-phone" party="PARTY_ID" type="TEXT" label="Phone"></sajn-field>. key names the field, and party is the party who fills it in. type is TEXT (default), DATE, or SELECT with its choices in options, separated by commas. A field is required unless you set required="false", and value prefills it. To fill a TEXT field from the party's eID verification, set identity to NAME or SSN; the party must open the document through an eID ACCESS gate that returns that value, and they can't change it. Responses return the same tag.

HTML Field Security: HTML fields accept raw HTML but are automatically sanitized server-side to allow only safe formatting tags (p, div, span, headings, lists, tables, images) and basic CSS styling. Links, script tags, and dangerous attributes are stripped. Images support HTTP/HTTPS URLs and data URIs for inline images.

Authorization

headerAuthorizationBearer <token>

API key, e.g. Authorization: Bearer sajn_svc_.... Not scope-limited: acts with its owner's workspace role.

Path Parameters

id*string

The document ID.

Header Parameters

Sajn-Version?string

API version for this request. Without it, the request uses the organization's default version; an organization without a default is pinned to the latest version by its first request.

Value in"2026-09""2026-10"
Sajn-Workspace?string

ID of the workspace this request acts in, from GET /api/v1/workspaces. Without it, an API key acts in its default workspace. The token's user must be a member of the workspace; an OAuth token only accepts the workspace it was granted for. A workspace that doesn't exist or can't be reached returns 403 WORKSPACE_ACCESS_DENIED.

Idempotency-Key?string

Makes retries safe. A retry with the same key and the same request replays the stored response for 24 hours (header Idempotent-Replayed: true); the same key with a different request returns 400.

Lengthlength <= 255

Request Body

Body

application/json
  1. body
content*array<>

The content blocks to create, in the order the response lists them

Items1 <= items

Response Body

200

application/json
  1. response
data*array<>

The created fields, in request order

Example Request
curl -X POST 'https://app.sajn.se/api/v1/documents/cm4k2x9p10003abcd1234efgh/content' \  -H 'Content-Type: application/json' \  -d '{  "content": [    {      "type": "TEXT",      "position": 0,      "fieldMeta": {        "type": "TEXT",        "content": "<p>Anställningen gäller tills vidare från och med den 1 november 2026, med sex månaders provanställning.</p>",        "locked": false,        "sectionStyle": {          "background": "NONE",          "padding": "NONE",          "bleed": false,          "border": false        },        "hidden": false      }    }  ]}'
Example Response
{  "data": [    {      "id": "cm4k2x9p10009abcd1234efgh",      "documentId": "cm4k2x9p10003abcd1234efgh",      "templateId": null,      "type": "TEXT",      "position": 0,      "fieldMeta": {        "type": "TEXT",        "content": "<p>Anställningen gäller tills vidare från och med den 1 november 2026, med sex månaders provanställning.</p>"      },      "createdAt": "2026-09-28T09:12:00.000Z",      "updatedAt": "2026-09-28T09:12:00.000Z"    }  ]}

Was this page helpful?