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
Always prefer
DocumentCard
unless you really need access topayload
Store any data you need later on in
meta
instead of (or in addition to)payload
that way you won't need access topayload
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
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
.
public_share_link
(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
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.
public_share_link
(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
.
Lists the DocumentCards for your Documents
GET
This endpoint is limited to 24 items and provides pagination data.
Query Parameters
Name | Type | Description |
---|---|---|
page[number] | Integer | Number of the page to show (default |
q[document_template_id] | Array<UUID> | List of Template IDs to filter on |
q[status] | String | Can be one of: • success • failure • draft |
q[workspace_id] | UUID | ID of a workspace to filter on |
q[updated_since] | Timestamp | Filter documents that have been updated after a given point in time (example |
Fetching a Document
Fetching a DocumentCard
Fetches the DocumentCard data for a given Document
GET
https://api.pdfmonkey.io/api/v1/document_cards/ID
Path Parameters
Name | Type | Description |
---|---|---|
ID* | UUID | ID of the Document to fetch |
Fetching a Document
Fetches the data for a given Document
GET
https://api.pdfmonkey.io/api/v1/documents/ID
Path Parameters
Name | Type | Description |
---|---|---|
ID* | UUID | ID of the Document to fetch |
Creating a Document
Creates a Document
POST
https://api.pdfmonkey.io/api/v1/documents
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | application/json |
Request Body
Name | Type | Description |
---|---|---|
document[document_template_id]* | UUID | ID of the source Template to use |
document[payload] | Object or String | Data to use for the Document generation. Can be either an Object or a string of JSON. Must be a single Object in any case. |
document[meta] | Object or String | Meta-Data to attach to the Document. Can be either an Object or a string of JSON. Must be a single Object in any case. |
document[status] | String | Can be one of:
• |
Example
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:
Create a Document and give it the
pending
statusUpdate an existing draft Document to give it the
pending
status
Updating a Document
Updates an existing Document
PUT
https://api.pdfmonkey.io/api/v1/documents/ID
Headers
Name | Type | Description |
---|---|---|
Content-Type* | String | application/json |
Request Body
Name | Type | Description |
---|---|---|
document[document_template_id] | UUID | ID of the source Template to use |
document[payload] | Object or String | Data to use for the Document generation. Can be either an Object or a string of JSON. Must be a single Object in any case. |
document[meta] | Object or String | Meta-Data to attach to the Document. Can be either an Object or a string of JSON. Must be a single Object in any case. |
document[status] | String | Can be one of:
• |
Deleting a Document
Deletes a Document
DELETE
https://api.pdfmonkey.io/api/v1/documents/ID
Path Parameters
Name | Type | Description |
---|---|---|
ID* | UUID | ID of the Document to delete |
Last updated