Webhook Events

PDF-Sign sends webhooks for various events. This page documents each event type and its payload structure.

Event Types

EventTriggerPriority
pdf.generatedPDF successfully createdHigh
pdf.failedPDF generation failedHigh
quota.warningUsage reached 80% of quotaMedium
quota.exceededMonthly quota limit reachedHigh

pdf.generated

Triggered when a PDF is successfully generated and stored.

Payload

{
  "event": "pdf.generated",
  "timestamp": "2024-01-15T10:30:45.123Z",
  "data": {
    "template_id": "550e8400-e29b-41d4-a716-446655440000",
    "pdf_url": "https://api.pdf-sign.com/storage/v1/object/public/pdfs/user-id/template-id/1705312245123.pdf",
    "storage_path": "user-id/template-id/1705312245123.pdf",
    "file_size": 156789,
    "render_time_ms": 2450,
    "variables": {
      "clientName": "John Doe",
      "invoiceNumber": "INV-2024-001",
      "amount": "1500.00"
    },
    "created_at": "2024-01-15T10:30:45.123Z"
  }
}

Fields

FieldTypeDescription
template_idstringUUID of the template used
pdf_urlstringPublic URL to download the PDF
storage_pathstringStorage path in the bucket
file_sizenumberPDF file size in bytes
render_time_msnumberTime to render the PDF in milliseconds
variablesobjectVariables used in the generation
created_atstringISO 8601 timestamp of creation

Example Use Cases

  • Download and process the generated PDF
  • Send the PDF to customers via email
  • Store metadata in your database
  • Trigger downstream workflows

pdf.failed

Triggered when PDF generation fails for any reason.

Payload

{
  "event": "pdf.failed",
  "timestamp": "2024-01-15T10:30:45.123Z",
  "data": {
    "template_id": "550e8400-e29b-41d4-a716-446655440000",
    "error_code": "RENDER_FAILED",
    "error_message": "Failed to render PDF: Template contains invalid HTML",
    "variables": {
      "clientName": "John Doe"
    }
  }
}

Fields

FieldTypeDescription
template_idstringUUID of the template that failed
error_codestringError code for programmatic handling
error_messagestringHuman-readable error description
variablesobjectVariables that were provided

Error Codes

CodeDescription
RENDER_FAILEDPDF rendering failed (invalid HTML, timeout, etc.)
STORAGE_FAILEDFailed to store PDF in storage
TEMPLATE_NOT_FOUNDTemplate does not exist
INVALID_VARIABLESVariables validation failed

Example Use Cases

  • Alert your team about failures
  • Retry the generation with corrected data
  • Log errors for debugging
  • Notify affected customers

quota.warning

Triggered when usage reaches 80% of the monthly quota.

One-Time Alert

This event is triggered once when crossing the 80% threshold, not on every request after that.

Payload

{
  "event": "quota.warning",
  "timestamp": "2024-01-15T10:30:45.123Z",
  "data": {
    "current_usage": 240,
    "quota_limit": 300,
    "percentage": 80,
    "subscription_plan": "starter"
  }
}

Fields

FieldTypeDescription
current_usagenumberCurrent number of PDFs generated this month
quota_limitnumberMaximum PDFs allowed per month
percentagenumberPercentage of quota used
subscription_planstringCurrent subscription plan

Example Use Cases

  • Send alert to administrators
  • Display warning in your application
  • Proactively upgrade the plan
  • Pause non-critical PDF generation

quota.exceeded

Triggered when the monthly quota limit is reached and a PDF generation is blocked.

Payload

{
  "event": "quota.exceeded",
  "timestamp": "2024-01-15T10:30:45.123Z",
  "data": {
    "current_usage": 300,
    "quota_limit": 300,
    "subscription_plan": "starter"
  }
}

Fields

FieldTypeDescription
current_usagenumberCurrent number of PDFs generated
quota_limitnumberMaximum PDFs allowed per month
subscription_planstringCurrent subscription plan

Example Use Cases

  • Immediately notify administrators
  • Trigger plan upgrade workflow
  • Pause PDF generation features
  • Queue PDFs for next month

Handling Multiple Events

You can subscribe to multiple events with a single webhook. Handle them using a switch statement:

app.post('/webhooks/pdf-sign', (req, res) => {
  const { event, data } = req.body;

  switch (event) {
    case 'pdf.generated':
      handlePdfGenerated(data);
      break;
    case 'pdf.failed':
      handlePdfFailed(data);
      break;
    case 'quota.warning':
      handleQuotaWarning(data);
      break;
    case 'quota.exceeded':
      handleQuotaExceeded(data);
      break;
    case 'test':
      console.log('Test webhook received');
      break;
    default:
      console.log(`Unknown event: ${event}`);
  }

  res.status(200).send('OK');
});

Event Timing

EventWhen It's Sent
pdf.generatedImmediately after successful storage
pdf.failedImmediately after failure detection
quota.warningWhen crossing 80% threshold
quota.exceededWhen a request is blocked due to quota

Async Delivery

Webhooks are sent asynchronously ("fire and forget") and do not block the API response. There may be a slight delay between the event and webhook delivery.