client.render.document
client.render.document(project:, template:, data:, format: nil, orientation: nil, locale: nil, metadata: nil, idempotency_key: nil) POST /v1/render — render and store the document, returning a
PoliPage::DocumentDescriptor with the client back-reference attached
so that #download_pdf works. The API renders the project’s copy
published in the API key’s environment; the SDK never sends an
environment. The request body holds only the seven render fields
(project, template, data, metadata, format, orientation,
locale); unset optional fields are omitted.
Parameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
project | String | required | project slug |
template | String | required | template slug inside the project |
data | Hash | required | template data, sent with its keys as given (never renamed) |
format | String, nil | — | one of `PoliPage::PageFormat::FORMATS`; API default when nil. Sent as given: the API answers another value with `400`. |
orientation | String, nil | — | "portrait" or "landscape"; API default when nil. Sent as given. |
locale | String, nil | — | BCP 47 (e.g. "en-US") |
metadata | Hash, nil | — | primitive-valued metadata, sent as is and echoed unchanged on the descriptor (String keys, as the API returns them) |
idempotency_key | String, nil | — | caller-supplied UUID; auto-generated if nil |
Returns
Section titled “Returns”PoliPage::DocumentDescriptor
Errors
Section titled “Errors”| Code | When |
|---|---|
PoliPage::ValidationError | See [errors](../../../production/errors/) for the full description. |
PoliPage::NotFoundError | See [errors](../../../production/errors/) for the full description. |
PoliPage::RateLimitError | See [errors](../../../production/errors/) for the full description. |
PoliPage::InvalidResponseError | See [errors](../../../production/errors/) for the full description. |
PoliPage::InternalError | See [errors](../../../production/errors/) for the full description. |
PoliPage::APIError | See [errors](../../../production/errors/) for the full description. |
Example
Section titled “Example”# frozen_string_literal: true
# Demonstrates: client.render.document — render and store the document on# Poli Page's servers. Returns a `PoliPage::DocumentDescriptor` with a# back-reference to the client so `#download_pdf` works.require "poli_page"
client = PoliPage::Client.new(api_key: ENV.fetch("POLI_PAGE_API_KEY"))
doc = client.render.document( project: "billing", template: "invoice", data: { invoiceNumber: "INV-001", total: 1280 }, metadata: { customerId: "cust_123" })
# `doc.document_id` is the stored document's identifier — use it with# `client.documents.*` to fetch, preview, thumbnail, or delete later.puts "stored as document #{doc.document_id} (#{doc.page_count} page(s))"
# Pull the PDF bytes via the (15-minute TTL) presigned URL.pdf = doc.download_pdfFile.binwrite("invoice.pdf", pdf)