- Double quotes in the HTML must be escaped in the JSON string.
- Editors output a full document with
<html>and<body>, but an HTML field holds a fragment. - Styles on
<body>, such as padding and fonts, are lost unless you move them to a wrapper element.
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
DRAFTdocument. For more information, see Create a document.
Send an HTML file
1
Extract the body and keep its styles
The following functions return the content of For example, the functions turn the following document:Into the following fragment:
<body>, wrapped in a <div> with the body’s style attribute. Content without a <body> tag with attributes is returned unchanged:2
Send the fragment as an HTML field
Build the body with your language’s JSON serializer, which escapes the quotes for you. Never build the JSON string by hand. The field goes in a Set
fields array:DOCUMENT_ID in the environment to the ID of the draft document. The response has the created field in data.Prepare the HTML
- Use inline
styleattributes only. sajn removes<style>tags, so styles from a stylesheet or a<head>are lost. - Split long content into several HTML fields, ordered by
position, instead of one large block. - Host images and reference them by
httpsURL instead of inlining them as base64.
Handle errors
400 INVALID_JSON: the body isn’t valid JSON, usually because of unescaped quotes. Serialize the body withJSON.stringifyorjson.400 VALIDATION_FAILEDonfields.0.fieldMeta.type:typeandfieldMeta.typemust both beHTML.
Next steps
HTML fields
See the allowed tags and CSS properties.
Send for signing
Send the document to its parties.

