apyhub
Back
▣ OUTPUT KIT

Generate Letter Document from JSON API

What it does

The Letter Generator API turns letter content in JSON into a formatted business letter. Send the sender, recipient, date and paragraphs, and get back a PDF, HTML or DOCX file.

Put the content in data. Required fields are the sender and recipient (each with a name and address lines), the date and the paragraphs. Optional fields add a subject, salutation, closing, signature and reference. Use page to set the paper size, margin and orientation.

Set format to pdf (default), html, docx or json. With json, the response includes the letter as a PDF data_uri plus metadata. Set download to true to get the file itself. The metadata reports the bytes, the pages count for PDF output, any render warnings, and timing in queued_ms and render_ms.

Teams use the Letter Generator API to send customer notices, engagement letters, internal approvals and mail merge exports from application data. Each letter comes out with the same layout, so printed and PDF letters stay consistent.

For your own letter design, fill a DOCX or HTML template with the Validate & Generate Documents from Templates API. For other document types, use the Generate Report Document from JSON API.

POST
Generate a preset document from JSON (letter)
https://api.eu.apyhub.com/callable-labs/generate-letter-document-from-json-api/v1/documents/preset/letter

QUICKSTART

GUIDE

Quickstart

Render a letter with the required sender, recipient, date, and body paragraphs.

curl -X POST "https://api.eu.apyhub.com/callable-labs/generate-letter-document-from-json-api/v1/documents/preset/letter" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "date": "18 September 2026",
      "sender": {
        "name": "Ada Lovelace"
      },
      "recipient": {
        "name": "Charles Babbage"
      },
      "paragraphs": [
        "Thank you for the drawings you sent last week.",
        "I believe the engine might act upon other things besides number."
      ]
    }
  }'

What you'll get back

Returns a JSON object with bytes and queued_ms/render_ms timing fields, plus cache, engine, format, data_uri, warnings, media_type, and engine_version. pages is an integer when the output is a PDF, or null for DOCX/HTML.

{
  "bytes": 12345,
  "cache": "miss",
  "pages": 2,
  "engine": "string",
  "format": "pdf",
  "data_uri": "data:application/pdf;base64,....",
  "warnings": [],
  "queued_ms": 12,
  "render_ms": 345,
  "media_type": "application/pdf",
  "engine_version": "string"
}
TRY ITLIVE · 200 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
LetterRequest*
LetterData*
Letter content.
Party*
VAT / tax registration number.
Party*
Paragraphs*
Body paragraphs.
PageOptions
Paper size and margins for PDF output.

About this endpoint

What it does

Generates a letter document from JSON input. You provide the letter content plus optional page and output settings, and the endpoint returns rendering metadata and, for document outputs, the generated payload details.

Request Body

ParameterTypeDescription
dataObjectLetter content. Includes sender, recipient, date, and paragraphs.
data.dateStringDate string. Max length 32.
data.senderObjectSender details. Includes name and optional contact/address fields.
data.sender.nameStringSender name. Max length 200.
data.sender.emailStringSender email. Max length 200. Default: null.
data.sender.phoneStringSender phone. Max length 64. Default: null.
data.sender.tax_idStringVAT / tax registration number. Max length 64. Default: null.
data.sender.addressString ArrayAddress lines. Max items: 8.
data.closingStringLetter closing. Default: Kind regards,. Max length 200.
data.subjectStringLetter subject. Max length 200. Default: null.
data.recipientObjectRecipient details. Includes name and optional contact/address fields.
data.recipient.nameStringRecipient name. Max length 200.
data.recipient.emailStringRecipient email. Max length 200. Default: null.
data.recipient.phoneStringRecipient phone. Max length 64. Default: null.
data.recipient.tax_idStringVAT / tax registration number. Max length 64. Default: null.
data.recipient.addressString ArrayAddress lines. Max items: 8.
data.referenceStringReference. Max length 64. Default: null.
data.signatureStringSignature name or text. Max length 200. Default: null.
data.paragraphsString ArrayBody paragraphs. Min items: 1, max items: 50.
data.salutationStringLetter salutation. Default: Dear Sir or Madam,. Max length 200.
pageObjectPaper size, margin, and orientation for PDF output.
page.sizeENUMAllowed values: A4, Letter, Legal, A3, A5. Default: A4.
page.margin_mmNumberUniform page margin in millimetres. Minimum 0, maximum 50. Default: 18.
page.orientationENUMAllowed values: portrait, landscape. Default: portrait.
formatENUMAllowed values: json, html, pdf, docx. Default: json. pdf, html or docx return the bytes; json returns a PDF data URI plus metadata.
downloadBooleanSend Content-Disposition: attachment so browsers save the file. Default: false.

Response

Returns a JSON object with bytes (integer), cache (string), pages (integer, nullable), engine (string), format (string), data_uri (string), warnings (array of strings), queued_ms (integer), render_ms (integer), media_type (string), and engine_version (string) fields. The format field is limited to docx, pdf, or html; pages is null for DOCX/HTML.

Replace the Response table with this, removing the Status Code column:

AttributeTypeDescription
bytesIntegerNumber of bytes in the generated output.
cacheENUMAllowed values: hit, miss.
pagesIntegerPDF page count; null for DOCX/HTML.
engineStringRendering engine name.
formatENUMAllowed values: docx, pdf, html.
data_uriStringData URI in the form data:<media_type>;base64,….
warningsString ArrayWarnings emitted during rendering.
queued_msIntegerTime spent queued, in milliseconds.
render_msIntegerTime spent rendering, in milliseconds.
media_typeStringMIME type of the generated output.
engine_versionStringRendering engine version.

Notes

When format is json, the response includes a PDF data URI plus metadata instead of raw bytes. The pages field can be null when the generated output is DOCX or HTML, so do not rely on it for those formats.

▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.