DocEngine

Docs

API & hosts

Four integration surfaces: this website’s authorised render API, an iframe designer / fill host, an embedded editor (Salesforce / custom app), and n8n’s DocEngine node for PDF generation.

1. Authorised API link (this website)

Create an API link on the dashboard after Mapping is saved on the template. The token is bound to one template.

  • POST /api/v1/render/preview → JSON { html } (or HTML)
  • POST /api/v1/render/pdf → application/pdf
  • GET /api/v1/render/template → template JSON (iframe fill)
  • POST /api/v1/render/document-pdf → PDF from a filled document snapshot
  • Auth: Authorization: Bearer de_…, Authorization: Basic (username ignored; password or username = token), or X-Api-Key
  • Body: { "payload": { … } }, optional hideEmptyValues

Preview

curl -X POST https://your-host/api/v1/render/preview \
  -H "Authorization: Bearer de_…" \
  -H "Content-Type: application/json" \
  -d '{ "payload": { "Name": "Acme", "Amount": 1200 } }'

PDF

curl -X POST https://your-host/api/v1/render/pdf \
  -H "Authorization: Bearer de_…" \
  -H "Content-Type: application/json" \
  -d '{ "payload": { "Name": "Acme", "Amount": 1200 } }' \
  --output document.pdf

# HTTP Basic — password = de_… token; username is ignored (any string)
# Salesforce Named Credential: password = token, username can be anything (e.g. api)
curl -X POST https://your-host/api/v1/render/pdf \
  -u "any:de_…" \
  -H "Content-Type: application/json" \
  -d '{ "payload": { "Name": "Acme", "Amount": 1200 } }' \
  --output document.pdf

Browser helper: /r/<token> — paste payload, preview HTML, download PDF. Mapping paths use $payload… (see editor Mapping UI).

2. Create template in iframe

CRM / parent backend creates a draft, opens the designer, and stores the new template token on Finish.

  1. Dashboard → Account API key (scope templates). Keep it on the CRM server.
  2. POST /api/v1/templates/init → draft template + dedicated token + embedUrl (mode=design).
  3. Parent opens that URL in an iframe.
  4. Save template posts docengine:complete with kind: "template", document (template JSON), token, and fillUrl. Persist the token for later fill / n8n / render.

Init

curl -X POST https://your-host/api/v1/templates/init \
  -H "Authorization: Bearer de_ACCOUNT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Intake form", "group": "Clinical", "description": "New patient intake", "embedOrigin": "https://your-app.example" }'

List templates

curl https://your-host/api/v1/templates \
  -H "Authorization: Bearer de_ACCOUNT_KEY"

curl "https://your-host/api/v1/templates?group=Clinical" \
  -H "Authorization: Bearer de_ACCOUNT_KEY"
  • GET /api/v1/templates → { templates, groups } (no layout JSON)
  • GET /api/v1/templates?group=Clinical — filter by group
  • GET /api/v1/templates/groups — group names only
  • Each template has name, description, group

Designer iframe

<iframe
  id="docengine"
  src="EMBED_URL_FROM_INIT"
  style="width:100%;height:80vh;border:0"
></iframe>
<script>
  window.addEventListener('message', (event) => {
    if (event.origin !== 'https://your-host') return;
    const msg = event.data;
    if (msg?.type === 'docengine:complete' && msg.kind === 'template') {
      // Persist msg.token + msg.templateId (and optionally msg.document)
      // Later fill: /embed/{token}?format=json
    }
  });
</script>

3. Iframe fill (this website)

Launch fill mode in a parent app and receive only the finished document — JSON values, HTML, or PDF. Create an API link, then:

/embed/<token>?format=json|html|pdf&origin=https://your-app.example
  • format — json (default), html, or pdf
  • json=values|document — values-only export (default) or full snapshot
  • origin — parent origin for postMessage (required in production)
  • hideEmpty=1 — omit empty fields from HTML/PDF/values

The iframe has no site chrome. Finish validates required fields, then posts docengine:complete. Opened outside an iframe, Finish downloads the file instead.

Parent page

<iframe
  id="docengine"
  src="https://your-host/embed/de_…?format=json&origin=https://your-app.example"
  style="width:100%;height:80vh;border:0"
></iframe>
<script>
  const iframe = document.getElementById('docengine');
  const DE = 'https://your-host';

  window.addEventListener('message', async (event) => {
    if (event.origin !== DE) return;
    const msg = event.data;
    if (msg?.type === 'docengine:ready') {
      iframe.contentWindow.postMessage(
        { type: 'docengine:init', payload: { Name: 'Acme' } },
        DE
      );
    }
    if (msg?.type === 'docengine:list-query') {
      const items = await fetchLists(msg); // [{ id, label }]
      iframe.contentWindow.postMessage(
        { type: 'docengine:list-result', requestId: msg.requestId, items },
        DE
      );
    }
    if (msg?.type === 'docengine:complete') {
      // msg.format: json | html | pdf
      // json → object (values by default)
      // html → string
      // pdf  → base64 string (msg.encoding === 'base64')
      console.log(msg.document);
    }
  });
</script>

Remote List/Choice fields call the parent with docengine:list-query. Answer with docengine:list-result and the same requestId (see Lists & queries). Optional docengine:init can prefill via Mapping (payload) and set format. After fill, the parent can request another artifact without reloading: { type: 'docengine:submit', format: 'html' | 'pdf' | 'json' }.

Local test page: /embed-test.html — Create template (account key) or load a fill token.

4. Embedded editor host

Use @docengine/editor (or the Salesforce Static Resource bundle). Important host hooks:

  • resolveListItems — remote List/Choice search
  • catalogs — shared lists/trees
  • imageUpload — durable image URLs
  • PDF — exportPdf / host generatePdfBlob
import { createEditor } from '@docengine/editor';

const editor = createEditor({
  holder: el,
  designMode: true,
  catalogs: { lists: {}, trees: {} },
  resolveListItems: async ({ query, sourceCollection }) => { /* … */ },
  ui: { designLayout: 'panels', showPreview: true },
});

await editor.ready;
const template = await editor.exportTemplate(); // kind: 'template'
await editor.applyFieldMapping(payload);        // needs fieldMapping on template
await editor.preview();
// PDF via host generatePdfBlob or exportPdf

Salesforce fills via buildPayload + applyFieldMapping, then Save / Finish + PDF. Remote lists use Apex DocEngineListController — see Lists & queries.

5. n8n DocEngine node (Salesforce & custom apps)

Preferred path when another system should produce the PDF file: Webhook → DocEngine node (template stored in node + Values expression) → binary document.pdf.

Point Salesforce Named Credential DocEngine_Pdf at that webhook (or use apps/pdf-service). Do not use the website API-link token for Salesforce PDF.

Walkthrough + screenshot: Examples → n8n.

Which path should I use?

  • CRM creating a new form — POST /api/v1/templates/init then iframe mode=design.
  • Humans filling inside another app — iframe /embed/<token>.
  • Humans designing/filling here — editor on this site or Salesforce LWC.
  • HTTP client + Mapping — authorised API link.
  • Salesforce / ERP generating files — n8n DocEngine node (or pdf-service).
  • Live picklists while filling — host resolveListItems or iframe list-query.