API
Create documents and PDFs from your own software: invoices from your accounting system, certificates for everyone on a course, a hundred name badges from a spreadsheet. The API is part of the Pro plan.
Keys
Create a key under API keys on your account page. It's shown once; keep it secret, like a password. Send it with every request:
curl https://craftadoc.com/api/v1/templates -H "Authorization: Bearer cdoc_..."
Up to 60 requests a minute. PDFs count towards your allowance of 500 per 5 hours and 2,000 per week; saved documents count towards your 10,000 documents (see limits). Errors come back as JSON with an error message, or problems for values that don't fit the template; over a limit, the status is 429 and the message says when there's room again.
Templates
GET /api/v1/templates?q=invoice&category=invoice lists matching templates: id, name, description, categories, sizes, language.
GET /api/v1/templates/{id} returns a template's form as a JSON Schema (schema), its example values and sizes. Your values follow the schema; limits such as the number of characters are in the field descriptions. Images and icons aren't part of it: they keep the template's own.
A PDF in one step
POST /api/v1/pdf turns values into a PDF without saving anything:
curl https://craftadoc.com/api/v1/pdf \
-H "Authorization: Bearer cdoc_..." \
-H "Content-Type: application/json" \
-d '{"templateId": "certificate", "size": "a4", "values": { ... }}' \
-o certificate.pdf
If the values don't fit, the answer is 422 with a list of problems, each with the field's path and a message.
Many PDFs: batches
For more than a few PDFs, start a batch: one request, and Craftadoc makes the PDFs in the background as one .zip.
curl https://craftadoc.com/api/v1/batches \
-H "Authorization: Bearer cdoc_..." \
-H "Content-Type: application/json" \
-d '{"templateId": "certificate", "size": "a4", "rows": [{"name": "Ada Lovelace", "values": { ... }}, ...]}'
Up to 1,000 rows; name becomes the file name in the .zip. The answer (202) has the batch's id. Follow it with GET /api/v1/batches/{id}: status goes from queued and running to done (or failed if no PDF could be made), with made, failed and the problems per row. Once done, downloadUrl gives the .zip; it works without a key, so you can pass it on. GET /api/v1/batches lists your batches.
The .zip and the values are removed after 3 days; nothing is saved in your account. All rows count towards your PDF allowance when the batch starts, and the ones that couldn't be made are given back. You can have 3 batches waiting or running at a time.
No code needed for a one-off batch: on a template's page, choose Make many to fill in a spreadsheet and get all the PDFs as one .zip.
Documents
Documents are saved in your account, where you can open them in the editor.
| Request | What it does |
|---|---|
POST /api/v1/documents | Create a document: {"templateId", "values", "title"?, "size"?}. Returns id, problems, editUrl and pdfUrl. |
GET /api/v1/documents?limit=20 | Your most recently changed documents |
GET /api/v1/documents/{id} | A document's values, problems and links |
PATCH /api/v1/documents/{id} | Change values (all of them), title or size |
GET /api/v1/documents/{id}/pdf | The document as a PDF |
DELETE /api/v1/documents/{id} | Delete a document |
POST /api/v1/documents/delete | Delete up to 100 documents: {"ids": [...]} |
Values that don't fit are still saved, as a draft, and returned as problems; the PDF is available once they're fixed. The pdfUrl works without a key for 24 hours, so you can pass it on.
Deleted documents go to Recently deleted in your account, where you can restore them on the site for 14 days; after that they're removed for good. They stop counting towards your limit straight away. Use documents for what people should be able to open and change later; for PDFs you only send on, use /api/v1/pdf or a batch, so nothing piles up.