API Guide
Automating PDF generation
Once you have finished setting up your documents you can use the PDFBlaze API to generate your PDFs.
You can retrieve the API key from the workspace settings page. The API key is used to authenticate your requests to the PDFBlaze API. To use the API, you will need to include the API key as a bearer in the Authorization
header of your requests.
To make a request that allows you to print a PDF, you will need to send a POST request to the /documents/slug/${document.slug}/print
endpoint. The document slug is the unique identifier of the document you want to print. You can find the slug of the document on the full list of documents in the workspace documents or by visiting the Generate
tab in the document editor.
To fill in any templated values the request should include a values
array in the request body. The values
array should contain the values for the templated content in the document. Each entry of values
is in the form of an object where the key is the templated object identifier and the value is the value you want to fill in. The templated content is defined using their templated
identifier in the document editor.
Any templated container in the document get expanded to a list of values instead of a single value. The templated container values should be in the form of a JSON array, where each object in the array is another JSON object that contains the values for the templated content in the container itself.
Examples
The following is a payload for a simple document with a single templated text object and generates 3 individual PDFs:
{
"values": [{
"my-text-field": "Foo",
}, {
"my-text-field": "Bar",
}, {
"my-text-field": "Baz",
}]
}
A more complex example with multiple templated objects and a templated container may look like this:
{
"values": [{
"username": "John Doe",
"address": "1234 Elm Street",
"items": [
{
"item-name": "Item 1",
"item-price": "$10.00"
},
{
"item-name": "Item 2",
"item-price": "$20.00"
}
]
}]
}
You may check the API reference for more information on the available endpoints and request payloads.