RistmarkStart free

Documentation

API quickstart: curl, Node and Python

Generate your first document with the Ristmark API in a few minutes. Every example below does the same three things: find an approved template, generate one PDF, generate a batch of two. For keys, every endpoint and every error code, see Generating with the /v1 API.

Before you start

  1. Create an API key in Settings → API Keys → Create and copy the plk_live_… key. It is shown once.
  2. Put it in your environment, never in source code:
export RISTMARK_API_KEY=plk_live_xxx
  1. Have at least one approved template. Only approved templates can be generated through the API.

Generating is billed to your plan per rendered page (Pricing & limits). Listing templates and exporting one are not billed.

1. Find a template id

curl https://api.ristmark.app/v1/templates \
  -H "Authorization: Bearer $RISTMARK_API_KEY"

The response is { "items": [{ "id": "…", "name": "Invoice", "latestVersion": 3 }] }. Copy the id of the template you want:

export TEMPLATE_ID=<id>

2. Generate one document

POST /v1/documents returns the rendered file itself, not JSON. Save it to disk. The data object holds the values the template binds to; leave it out to render the template’s sample data.

curl

curl -sS --fail-with-body -X POST https://api.ristmark.app/v1/documents \
  -H "Authorization: Bearer $RISTMARK_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"templateId\":\"$TEMPLATE_ID\",\"format\":\"pdf\",\"data\":{\"invoiceNo\":\"NW-2026-0184\"}}" \
  -D headers.txt -o out.pdf

--fail-with-body makes curl exit non-zero on an error status instead of saving the error as out.pdf. headers.txt holds the response headers, including X-Ristmark-Render-Warnings.

Use your template’s own field names in data. invoiceNo is a placeholder. A value the template reads that is missing from data renders blank, and the render says so in X-Ristmark-Render-Warnings (unresolved-bindings:N). To learn the keys a template expects, export it. Once your data is right, add "strict": true to the request: a render with a missing or broken value is then refused with 422 render_unresolved instead of returning a best-effort document.

Node.js

Node 18 or newer, no packages needed. Save as generate.mjs and run node generate.mjs.

import { writeFile } from "node:fs/promises";

const key = process.env.RISTMARK_API_KEY;
const templateId = process.env.TEMPLATE_ID;

const res = await fetch("https://api.ristmark.app/v1/documents", {
  method: "POST",
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    templateId,
    format: "pdf",
    data: { invoiceNo: "NW-2026-0184" },
  }),
});
if (!res.ok) {
  const err = await res.json().catch(() => ({}));
  throw new Error(`${res.status} ${err.code ?? ""} ${err.message ?? ""}`);
}
console.log("warnings:", res.headers.get("x-ristmark-render-warnings"));
await writeFile("out.pdf", Buffer.from(await res.arrayBuffer()));

Python

Python 3 with pip install requests. Save as generate.py and run python generate.py.

import os
import requests

key = os.environ["RISTMARK_API_KEY"]
template_id = os.environ["TEMPLATE_ID"]

res = requests.post(
    "https://api.ristmark.app/v1/documents",
    headers={"Authorization": f"Bearer {key}"},
    json={
        "templateId": template_id,
        "format": "pdf",
        "data": {"invoiceNo": "NW-2026-0184"},
    },
    timeout=60,
)
if not res.ok:
    raise SystemExit(f"{res.status_code} {res.text}")
print("warnings:", res.headers.get("X-Ristmark-Render-Warnings"))
with open("out.pdf", "wb") as f:
    f.write(res.content)

3. Generate a batch

POST /v1/documents/batch takes up to 25 items, each { templateId, data, format?, version? }, and returns JSON with one result per item. Each rendered document comes back as base64 in document. One failed item never fails the others, so check every item’s status.

curl

curl -sS --fail-with-body -X POST https://api.ristmark.app/v1/documents/batch \
  -H "Authorization: Bearer $RISTMARK_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"items\":[{\"templateId\":\"$TEMPLATE_ID\",\"data\":{\"invoiceNo\":\"A-1\"}},{\"templateId\":\"$TEMPLATE_ID\",\"data\":{\"invoiceNo\":\"A-2\"}}]}" \
  -o batch.json

Node.js

Add this to the end of generate.mjs; it reuses key, templateId and writeFile from above.

const batchRes = await fetch("https://api.ristmark.app/v1/documents/batch", {
  method: "POST",
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    items: [
      { templateId, data: { invoiceNo: "A-1" } },
      { templateId, data: { invoiceNo: "A-2" } },
    ],
  }),
});
if (!batchRes.ok) throw new Error(`batch failed: ${batchRes.status}`);
const batch = await batchRes.json();
for (const r of batch.results) {
  if (r.status === "ok") {
    await writeFile(`batch-${r.index}.${r.format}`, Buffer.from(r.document, "base64"));
  } else {
    console.error(`item ${r.index} failed: ${r.error.code} ${r.error.message}`);
  }
}

Python

Add this to the end of generate.py; it reuses key and template_id from above.

import base64

res = requests.post(
    "https://api.ristmark.app/v1/documents/batch",
    headers={"Authorization": f"Bearer {key}"},
    json={
        "items": [
            {"templateId": template_id, "data": {"invoiceNo": "A-1"}},
            {"templateId": template_id, "data": {"invoiceNo": "A-2"}},
        ]
    },
    timeout=60,
)
res.raise_for_status()
for r in res.json()["results"]:
    if r["status"] == "ok":
        with open(f"batch-{r['index']}.{r['format']}", "wb") as f:
            f.write(base64.b64decode(r["document"]))
    else:
        print(f"item {r['index']} failed: {r['error']['code']} {r['error']['message']}")

What to handle

  • 429 rate limited. Generation is limited to 30 requests a minute per workspace. Wait for the number of seconds in the Retry-After header, then retry. Retry nothing else blindly.
  • 402 quota_exceeded. Your plan is inactive or out of generation allowance.
  • 422 render_unresolved. strict: true refused the render. The body’s diagnostics array names each problem.
  • A batch item with status: "error". Its error.code and error.message say why; the other items are unaffected.

Every status and render warning is listed in Limits & errors and Render warnings. Have many rows in a spreadsheet instead? See Generate from a spreadsheet.