Templates
Get a list of available templates
To get all templates, send a GET request to
/api/templates
. You will receive a JSON response containing all templates.
GET /api/templates
Headers |
|
Authorization* |
The
|
Content-Type |
Default: application/json
The
|
Example Request
Here is an example of a GET request to the templates endpoint. In this example, we are using the
curl
command-line tool to send a GET request to the API.
curl -X GET "https://pdf-api.io/api/templates" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {token}"
Example Response
The response will be a JSON array containing template objects. Each template object includes the following fields:
id
: The unique identifier of the templatename
: The name of the templatetype
: The type of the template (e.g., "editor" or "html")created_at
: The creation date of the templatemeta
: Additional metadata associated with the templatevariables
: An array of variables used in the template
Here's an example of the response structure:
[
{
"id": "1234567890",
"name": "Invoice Template",
"type": "editor",
"created_at": "2023-04-15T10:30:00Z",
"meta": {
"description": "A simple invoice template"
},
"variables": [
{
"name": "customer_name",
"type": "string"
},
{
"name": "invoice_items",
"type": "array"
},
{
"name": "invoice_items[]",
"type": "object"
},
{
"name": "invoice_items[].description",
"type": "string"
},
{
"name": "invoice_items[].amount",
"type": "string"
}
]
}
]
Understanding the
variables
Field
The
variables
field provides information about the dynamic content that can be inserted into the template. Each variable object in the array contains:
name
: The name of the variable, which can be used to populate the template with datatype
: The expected data type of the variable (e.g., "string", "array", or "object")
For array variables, you'll notice three related entries:
- The array itself (e.g.,
invoice_items
) - An entry for the array items (e.g.,
invoice_items[]
) - Individual fields within the array items (e.g.,
invoice_items[].description
)
This structure allows you to understand how to format your data when using the template, especially for complex structures like tables or repeatable sections.