Generate and download a document

Create or select a template in your account. Match merge_parameters to its merge-variable names. Use an empty object when the template has no merge variables.

curl --fail-with-body --request POST \
  "$INKIT_BASE_URL/api/v1/generate" \
  --header "X-Inkit-API-Token: $INKIT_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "template_id": "tmpl_REPLACEWITHYOURTEMPLATEID",
    "merge_parameters": {},
    "destinations": {"inkit_storage": {"name": "Generated document"}}
  }'

POST /api/v1/renders is an alias for the same operation. The server automatically adds Inkit Storage when omitted.

A successful 201 response contains an id for the render, a file_id for the stored file, and a document_id for the document. Destination-specific identifiers appear when those destinations are included. These are different resource identifiers; do not interchange them.

Poll using the render id:

curl --fail-with-body "$INKIT_BASE_URL/api/v1/renders/$INKIT_RENDER_ID" \
  --header "X-Inkit-API-Token: $INKIT_API_KEY"

Inspect status, destination_status, and destinations. A successful create response means processing was queued; it does not mean rendering or delivery has completed. Poll at a bounded interval and stop on failure or your application timeout.

After completion, download raw document bytes using the document_id:

curl --fail-with-body \
  "$INKIT_BASE_URL/api/v1/documents/$INKIT_DOCUMENT_ID/download" \
  --header "X-Inkit-API-Token: $INKIT_API_KEY" \
  --output generated.pdf

Alternatively, GET /api/v1/files/download/{file_id} returns a JSON object, with base64 data in file, plus file_name and mime_type. Decode file before saving it. Do not save this JSON response directly as a PDF.

Downloads can return 423 while processing and 410 after expiration. Use files and documents to choose the appropriate resource API.


Did this page help you?