apyhub
Back

Generate Letter Document from JSON API

What it does

Letter Document Generator turns structured letter content into a rendered document. Send a body object with data, plus optional page and output settings, and get back a letter in pdf, html, or docx form. If you choose json, the response includes a PDF data URI and render metadata.

Use it when you need to create formal correspondence from application data: customer notices, engagement letters, internal approvals, or mail-merge style exports. The letter payload accepts the sender and recipient parties, date, paragraphs, and optional fields such as subject, salutation, closing, signature, and reference. You can also control paper size, margin, and orientation through the page object.

The response includes the generated file’s format, media_type, bytes, engine, engine_version, cache, and timing fields such as queued_ms and render_ms. For PDF output, it can also return pages; if rendering produces issues or notes, they appear in warnings.

Use Letter Document Generator when your backend needs a consistent, template-free way to produce printable business letters from JSON.

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.