Documents

Two Objects To Know

When you interact with your Documents, there are two objects you need to be aware of: Document and DocumentCard.
The main distinction between the two is that DocumentCard does not include the payload attribute of the Document. This matters because in many cases, this attribute will have a important size and will thus have an impact on performance on both your side and ours.

Rules of thumb

  1. 1.
    Always prefer DocumentCard unless you really need access to payload
  2. 2.
    Store any data you need later on in meta instead of (or in addition to) payload that way you won't need access to payload

The Document object

The Document object represents a single document (PDF), with its status, data and meta-data. It is used to manipulate the data used to generate a PDF.

Attributes

Document JSON
1
{
2
"id": "11475e57-0334-4ad5-8896-9462a2243957",
3
"app_id": "c2b67b84-4aac-49ea-bed8-69a15d7a65d3",
4
"checksum": "c230530f6f0aa32900af0924cf228e5c",
5
"created_at": "2022-04-07T11:01:38.201+02:00",
6
"document_template_id": "96611e9e-ab03-4ac3-8551-1b485210c892",
7
"download_url": "https://pdfmonkey.s3.eu-west-1.amazonaws.com/production/backend/document/11475e57-0334-4ad5-8896-9462a2243957/my-test-document.pdf?response-content-disposition=attachment&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ2ZTKW4HMOLK63IQ%2F20220406%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20220407T204150Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=24e3a8c0801ad8d1efd6aaa22d946ee70f5c8d5b55c586f346a094afa5046c77",
8
"failure_cause": null,
9
"filename": "my-test-document.pdf",
10
"generation_logs": [
11
{
12
"type": "info",
13
"message": "Starting PDF generation.",
14
"timestamp": "Thu, 07 Apr 2022 09:01:39 GMT"
15
},
16
{
17
"type": "info",
18
"message": "CONTEXT: {\n origin: 'backend',\n type: 'document',\n id: '11475e57-0334-4ad5-8896-9462a2243957',\n filename: 'my-test-document.pdf'\n}",
19
"timestamp": "Thu, 07 Apr 2022 09:01:39 GMT"
20
},
21
{
22
"type": "info",
23
"message": "Generation took 1617ms to load and render.",
24
"timestamp": "Thu, 07 Apr 2022 09:01:40 GMT"
25
},
26
{
27
"type": "info",
28
"message": "Content size is 96302.",
29
"timestamp": "Thu, 07 Apr 2022 09:01:40 GMT"
30
},
31
{
32
"type": "info",
33
"message": "Document stored as production/backend/document/11475e57-0334-4ad5-8896-9462a2243957/my-test-document.pdf",
34
"timestamp": "Thu, 07 Apr 2022 09:01:40 GMT"
35
}
36
],
37
"meta": "{ \"_filename\":\"my-test-document.pdf\" }",
38
"payload": "{ \"name\": \"Peter Parker\" }",
39
"preview_url": "https://preview.pdfmonkey.io/pdf/web/viewer.html?file=https%3A%2F%2Fpreview.pdfmonkey.io%2Fdocument-render%2F11475e57-0334-4ad5-8896-9462a2243957%2Fc230530f6f0aa32900af0924cf228e5c",
40
"public_share_link": "https://files.pdfmonkey.io/share/72BE2293-D130-4C19-9E11-C82B5CEA8C37/my-test-document.pdf",
41
"status": "success",
42
"updated_at": "2022-04-07T11:01:41.181+02:00"
43
}
Copied!

id

(String, UUID) Unique identifier for the object.

app_id

(String, UUID) Unique identifier of the Document's Workspace.

checksum

(String) Internal checksum of the Document's content, mainly used for the Document's preview.

created_at

(String, Date) Time at which the object was created.

document_template_id

(String, UUID) Unique identifier of the Document's Template.

download_url

(String, URL) The URL at which the Document can be downloaded.
Valid for 1 hour
Any time you fetch the details of a document, you get a fresh download URL. It is valid for 1 hour. Once that time has passed, you'll need to fetch the Document's details again to get a fresh URL.

failure_cause

(String) In case the Document's status is failure, this field will contain the reason of the failure. In any other case, this will be null.

filename

(String) Name of the generated file when the Document's status is success, will be null otherwise.

generation_logs

(Array of Objects) Logs collected during the Document's generation. Can be especially useful in case of generation failure.
type: Can be info or error message: The log message timestamp: The date and time of the log message
Will default to an empty array [] before the generation.

meta

(String, JSON) The meta-data of the Document. Can be null or an arbitrary object containing data that you want to attach to a Document. This can be useful when using integrations, like Zapier or Integromat, as the payload will not be accessible.

payload

(String, JSON) The dynamic data used to build the content of the Document. Must represent a JSON object, not an array.

preview_url

(String, URL) This URL is especially useful if you want to embed a preview of the PDF in your own UI. A good example of this is the preview in our own dashboard, when you create a new Document.
This is not a Download URL!
This attributes is often mixed up with the Download URL but it cannot be used to download a generated PDF, it should only be used in an iframe.
(String, URL) This URL will be present if your account has Share Links enabled. It is a permalink to the generated PDF.
Premium plan only
The share links feature is only available for Premium plans.

status

(String) Represents the current status of the Documents. You can learn more in the Document Lifecycle documentation page.

updated_at

(String, Date) Time at which the object was last updated.

The DocumentCard object

The DocumentCard object is a lightweight version of the Document. It contains almost the same information but excludes the payload.

Attributes

DocumentCard JSON
1
{
2
"id": "11475e57-0334-4ad5-8896-9462a2243957",
3
"app_id": "c2b67b84-4aac-49ea-bed8-69a15d7a65d3",
4
"created_at": "2022-04-07T11:01:38.201+02:00",
5
"document_template_id": "96611e9e-ab03-4ac3-8551-1b485210c892",
6
"document_template_identifier": "My Awesome Template",
7
"download_url": "https://pdfmonkey.s3.eu-west-1.amazonaws.com/production/backend/document/11475e57-0334-4ad5-8896-9462a2243957/my-test-document.pdf?response-content-disposition=attachment&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ2ZTKW4HMOLK63IQ%2F20220406%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20220407T204150Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=24e3a8c0801ad8d1efd6aaa22d946ee70f5c8d5b55c586f346a094afa5046c77",
8
"failure_cause": null,
9
"filename": "my-test-document.pdf",
10
"meta": "{ \"_filename\":\"my-test-document.pdf\" }",
11
"public_share_link": "https://files.pdfmonkey.io/share/72BE2293-D130-4C19-9E11-C82B5CEA8C37/my-test-document.pdf",
12
"status": "success",
13
"updated_at": "2022-04-07T11:01:41.181+02:00"
14
}
Copied!

id

(String, UUID) Unique identifier for the object.

app_id

(String, UUID) Unique identifier of the Document's Workspace.

created_at

(String, Date) Time at which the object was created.

document_template_id

(String, UUID) Unique identifier of the Document's Template.

document_template_identifier

(String) The name you gave to the Document's Template.

download_url

(String, URL) The URL at which the Document can be downloaded.
Valid for 1 hour
Any time you fetch the details of a document, you get a fresh download URL. It is valid for 1 hour. Once that time has passed, you'll need to fetch the Document's details again to get a fresh URL.

failure_cause

(String) In case the Document's status is failure, this field will contain the reason of the failure. In any other case, this will be null.

filename

(String) Name of the generated file when the Document's status is success, will be null otherwise.

meta

(String, JSON) The meta-data of the Document. Can be null or an arbitrary object containing data that you want to attach to a Document. This can be useful when using integrations, like Zapier or Integromat, as the payload will not be accessible.
(String, URL) This URL will be present if your account has Share Links enabled. It is a permalink to the generated PDF.
Premium plan only
The share links feature is only available for Premium plans.

status

(String) Represents the current status of the Documents. You can learn more in the Document Lifecycle documentation page.

updated_at

(String, Date) Time at which the object was last updated.

Listing Documents

In most cases, when listing Documents, you will only need to use DocumentCards.
get
Lists the DocumentCards for your Documents

Fetching a Document

Fetching a DocumentCard

get
https://api.pdfmonkey.io/api/v1/document_cards/ID
Fetches the DocumentCard data for a given Document

Fetching a Document

get
https://api.pdfmonkey.io/api/v1/documents/ID
Fetches the data for a given Document

Creating a Document

post
https://api.pdfmonkey.io/api/v1/documents
Creates a Document

Example

1
POST https://api.pdfmonkey.io/api/v1/documents
2
Authorization: Bearer YOUR_API_KEY
3
Content-Type: application/json
4
{
5
"document": {
6
"document_template_id": "12345678-90ab-cdef-1234-567890abcdef",
7
"payload": {
8
"name": "Jane Doe"
9
},
10
"meta": {
11
"clientId": "ABC1234-DE",
12
"_filename": "my-document.pdf"
13
}
14
}
15
}
Copied!

Attaching meta data to the Document

In addition to the Document’s payload you can add meta data when generating a Document.
This can be done by passing the document[meta] attribute. It can contain special keys to influence the generated filename for instance.

Generating the Document upon creation

If you want to generate the Document in one go, you can set its status to pending. Doing so, the Document will be queued for generation directly.

Generating a Document

To generate a Document you can either:

Updating a Document

put
https://api.pdfmonkey.io/api/v1/documents/ID
Updates an existing Document

Deleting a Document

delete
https://api.pdfmonkey.io/api/v1/documents/ID
Deletes a Document