Reacting to generated documents in n8n

PDFMonkey can notify your n8n workflows whenever a document is generated. This is perfect for automating actions after PDF generation, like storing files, sending notifications, or updating databases.

What is the PDFMonkey Trigger?

The PDFMonkey Trigger is a webhook-based trigger that listens for document generation events from PDFMonkey. When a document is successfully generated, PDFMonkey sends a notification to your n8n workflow.

Setting up the trigger

Step 1: Add the PDFMonkey Trigger node

  1. In your n8n workflow, click + to add a new node

  2. Search for PDFMonkey Trigger

  3. Select it as your workflow's starting point

Step 2: Configure your credentials

Select your PDFMonkey API credentials (the same ones used for the regular PDFMonkey node).

Step 3: Choose which templates to listen to

You have three options:

  • Any Template - Trigger for all documents generated in your workspace

  • Specific Template - Trigger only for a single template

  • Multiple Templates - Trigger for several selected templates

Selecting templates in PDFMonkey Trigger

Step 4: Configure the webhook in PDFMonkey

The trigger node will display a Webhook URL. You need to add this URL to your PDFMonkey template:

  1. Copy the webhook URL from the n8n trigger node

  2. Navigate to the Webhooks section

  3. Create a new endpoint

  4. Add the n8n webhook URL

  5. Check the events success and failure

  6. Press the Create button

Production vs Test webhooks

n8n provides two URLs:

  • Test URL: For testing in the n8n editor

  • Production URL: For activated/published workflows

Make sure to update your PDFMonkey webhook URL when activating your workflow!

Step 5: Activate your workflow

Click the Activate toggle in the top-right corner of n8n to enable your workflow.

What data is provided by the trigger?

When a document is generated, the trigger provides:

{
  "id": "doc_abc123",
  "status": "success",
  "filename": "invoice-2024.pdf",
  "download_url": "https://...",
  "preview_url": "https://...",
  "template_id": "tmpl_xyz789",
  "metadata": {
    "orderId": "12345",
    "customField": "value"
  },
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:05Z"
}

Auto-download feature

The PDFMonkey Trigger has a useful Download File option that automatically downloads the PDF when the trigger fires.

When enabled:

  • The PDF is downloaded as binary data

  • Available immediately in the next nodes

  • No need for a separate Download File operation

To enable it:

  1. Open the trigger node settings

  2. Expand Additional Options

  3. Toggle Download File to ON

The binary data will be available with the key data.

Use cases

Example 1: Store PDFs in Google Drive

1. PDFMonkey Trigger (Download File: enabled)
2. Google Drive - Upload File
   - File: {{ $binary.data }}
   - Folder: /Invoices/
   - Filename: {{ $json.filename }}

Example 2: Send notification to Slack

1. PDFMonkey Trigger
2. Slack - Send Message
   - Channel: #notifications
   - Message: "New PDF generated: {{ $json.filename }}"
   - Attachment: {{ $json.download_url }}

Example 3: Update database record

1. PDFMonkey Trigger
2. Postgres - Update
   - Table: orders
   - Where: id = {{ $json.metadata.orderId }}
   - Set: pdf_url = {{ $json.download_url }}, status = 'completed'

Example 4: Email PDF to customer

1. PDFMonkey Trigger (Download File: enabled)
2. Gmail - Send Email
   - To: {{ $json.metadata.customerEmail }}
   - Subject: Your invoice is ready
   - Attachments: {{ $binary.data }}

Using metadata for routing

Metadata is extremely useful for conditional workflows. Here's an example:

When generating the document:

{
  "metadata": {
    "documentType": "invoice",
    "customerId": "12345",
    "sendEmail": true
  }
}

In your triggered workflow:

1. PDFMonkey Trigger
2. IF node
   - Condition: {{ $json.metadata.sendEmail }} = true
   - TRUE: Send email with PDF
   - FALSE: Just store in database

Or route by document type:

1. PDFMonkey Trigger
2. Switch node
   - Case 1: {{ $json.metadata.documentType }} = "invoice" → Store in accounting
   - Case 2: {{ $json.metadata.documentType }} = "report" → Share on Slack
   - Case 3: {{ $json.metadata.documentType }} = "contract" → Store in DocuSign

Testing your trigger

Method 1: Generate a test document

The easiest way to test is to generate a document:

  1. Use another workflow or the API to generate a document

  2. Wait for the webhook to fire

  3. Check the trigger node execution in n8n

Method 2: Use the test webhook

  1. Click Listen for event in the trigger node

  2. Generate a document from your PDFMonkey template

  3. The trigger will catch the event and display the data

  4. Click Use test event to use this data while building your workflow

Multiple triggers for the same template

You can have multiple n8n workflows listening to the same template. Each webhook will receive the notification independently.

This is useful for:

  • Separating production and staging environments

  • Having different workflows for different document types

  • A/B testing different automation strategies

Webhook delivery guarantees

PDFMonkey webhooks are delivered with:

  • At-least-once delivery: You might receive the same event multiple times

  • Best-effort ordering: Events are usually in order but not guaranteed

  • 5-second timeout: The webhook request will timeout after 5 seconds

  • 3 retry attempts: Failed webhooks are retried with exponential backoff

Make your workflow idempotent

Since webhooks might be delivered multiple times, design your workflow to handle duplicate events gracefully. Use document IDs to check if you've already processed an event.

Troubleshooting

Webhook not firing

  1. Check your workflow is activated - The workflow must be active, not just saved

  2. Verify the webhook URL - Make sure the URL in PDFMonkey matches n8n's production URL

  3. Check template is published - Unpublished templates don't send webhooks

  4. Look at PDFMonkey webhook logs - Available in your template settings

Documents generated but trigger doesn't execute

  1. Check n8n execution logs - Look for errors in the workflow executions

  2. Verify credentials - Make sure your PDFMonkey credentials are valid

  3. Check template filter - If filtering by template, ensure it's the right one

Binary data not available

Make sure Download File is enabled in the trigger node's additional options.

Document generation options in n8nWebhooks

Last updated

Was this helpful?