Render with inline HTML
Send the HTML in the request when you generate it yourself, when it comes from another system, or when you want a one-off document and nothing to maintain in the portal.
curl -X POST https://api.example.com/v1/render \ -H "Authorization: Bearer $RUSTEDF_KEY" \ -H "Content-Type: application/json" \ -d '{ "html": "<h1>Hello {{ name }}</h1><p>{{ total | currency(code=\"USD\") }}</p>", "data": { "name": "World", "total": "1234.50" }, "locale": "en-US" }' \ -o hello.pdfThe html field is a template, just like a saved one: {{ }}, {% %} and the formatting
filters all work (see Templates). If your HTML is already final, with
no placeholders, send it as is and leave data out.
Building the request
Section titled “Building the request”Do not paste data into the HTML string yourself; pass it in data so it is escaped. In
Node.js:
const response = await fetch('https://api.example.com/v1/render', { method: 'POST', headers: { Authorization: `Bearer ${process.env.RUSTEDF_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ html: '<h1>{{ title }}</h1><ul>{% for i in items %}<li>{{ i }}</li>{% endfor %}</ul>', data: { title: 'Shopping list', items: ['Bread', 'Milk'] }, }),});Things to know
Section titled “Things to know”- Send
htmlortemplate_id, never both and never neither: that is a400. - Nothing is saved. There is no version and no preview in the portal; the HTML is sent again on every request, and the size limit of your plan applies to it.
- Images must be uploaded assets (
asset:<id>) ordata:URLs; see Images. - Use
/v1/validatewith the same body to check the document without using a credit.
When the same layout is generated often, a saved template is easier to keep. The request and response are described in Rendering a PDF.