Template Export

Export a template as a PDF or plain text file programmatically.

Overview

The export endpoint compiles one of your templates and returns it as a downloadable file. You supply the template's variables in the request body, and the rendered document is returned in the format you request.

All requests must be authenticated with an API key. See Authentication for how to create one.

Endpoint

POST /api/tasks/{templateId}/export

Replace {templateId} with the ID of the template you want to export.

Query parameters

  • format — the output format, either pdf or txt. Defaults to pdf when omitted.

Request body

The body is a JSON object with a single variables field. It maps each variable name to a string or boolean value. Any variables you omit fall back to the template's configured defaults.

Body schema
{
  "variables": {
    "<variable-name>": "<string | boolean>"
  }
}

If your template has no variables, send an empty object: { "variables": {} }.

Example

cURL
curl -X POST \
  "https://www.hardcopies.net/api/tasks/TEMPLATE_ID/export?format=pdf" \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "variables": { "includeNotes": true, "owner": "Alex" } }' \
  --output tasks.pdf

Response

On success the endpoint returns 200 OK with the rendered file as the body. The response is sent as an attachment named tasks-YYYY-MM-DD.pdf or tasks-YYYY-MM-DD.txt depending on the requested format.

FormatContent-Type
pdfapplication/pdf
txttext/plain

Errors

Errors are returned as JSON with an error message. Validation errors also include an issues array describing what went wrong.

StatusDescription
400 Bad RequestThe request body is malformed, or the supplied variables are invalid or fail to compile the template.
401 UnauthorizedThe API key is missing or invalid.
404 Not FoundNo template matches the given templateId.
429 Too Many RequestsThe API key has exceeded its rate limit.
500 Internal Server ErrorAn unexpected error occurred while generating the export.