Skip to main content

Webhooks

Webhooks allow you to receive real-time updates about results (and soon statuses) from the Parcha API. This guide explains how to use webhooks, including how to set them up, secure them with HMAC signatures, and test them.

Setting Up Webhooks

Parcha API supports two types of webhooks:
  1. Job Webhooks (webhook_url): Receive notifications when the entire job is completed
  2. Tool Webhooks (tool_webhook_url): Receive real-time updates each time an LLM tool is executed during the job
You can specify either or both webhook URLs when initiating a job:

Webhook Payloads

Job Webhook Payload

When a job is completed, Parcha API sends a POST request to your webhook URL with a payload containing job status information. Note: The webhook payload contains job status updates only, not the full check results.

Fetching Full Check Results

To get the complete check results after receiving a webhook notification, use the getJobById endpoint with include_check_results=true:
Process webhook payloads quickly and asynchronously. Use the job_id from the webhook to fetch full results via the API when needed.

Tool Webhook Payload

Tool webhooks provide real-time updates for individual tool executions. You can filter events by tool ID. For example, kyb.incorporation_document_extractor provides events related to incorporation document checks in the following order:
  1. Text extraction results (fastest)
  2. Visual verification
  3. Fraud detection (slowest)
Here are examples of different tool webhook payloads:

Text Extraction Results

The text extraction event is typically the fastest and includes important validation and extracted data fields:
Key fields in the extraction results include:
  • is_valid_document: Boolean indicating if the document is a valid incorporation document
  • business_name: The primary name of the business
  • all_business_names: Array of all business names found in the document
  • incorporation_date: The date of incorporation
  • business_address: The primary business address
  • all_extracted_addresses: Object containing all addresses found in the document, categorized by type
  • business_activity: The stated purpose or activity of the business
  • jurisdiction: The jurisdiction where the business is incorporated
  • business_registration_number: Array of registration numbers found in the document

Visual Verification Results

Fraud Detection Results

HMAC Signature Verification

To ensure the security and authenticity of webhook payloads, Parcha API signs each webhook request with HMAC-SHA256 signatures. Two signatures are provided in the webhook request headers:
  1. Standard Signature (X-Signature-SHA256): Signs the entire JSON payload
  2. Compact Signature (parcha-signature-compact): Signs only the case ID for lightweight verification

Standard Signature Verification

The standard signature is included in the X-Signature-SHA256 header and covers the entire request body. To verify the standard signature:
  1. Compute the HMAC-SHA256 signature of the raw request body using your API secret key.
  2. Compare this computed signature with the one in the X-Signature-SHA256 header.
Here’s an example of how to verify the signature in Python:

Parcha Compact Signature

The compact signature provides a lightweight alternative for verifying webhook authenticity without needing to process the entire payload. This signature is included in the parcha-signature-compact header and signs only the case ID from input_payload.id. When to use the compact signature:
  • When you need quick verification before processing large payloads
  • When you want to validate the webhook source using only the case ID
  • For implementing rate limiting or deduplication based on case ID
  • When you need to verify webhooks in environments with limited payload access
How the compact signature is generated:
  1. Extract the id field from input_payload in the webhook payload
  2. Compute HMAC-SHA256 of the ID string using your API secret key
  3. Base64 encode the resulting digest
Here’s an example of how to verify the compact signature:
Important notes:
  • The compact signature is only present when the payload contains input_payload.id
  • Both signatures use the same API secret key
  • The compact signature signs the string representation of the case ID
  • Always use constant-time comparison (hmac.compare_digest or crypto.timingSafeEqual) to prevent timing attacks
  • The compact signature is useful for quick validation, but you should still verify the full signature for complete payload integrity

Testing Your Webhooks

Parcha API provides a /api/v1/testWebhook endpoint to help you test both job and tool webhooks. This endpoint sends sample payloads to your specified webhook URLs.
The test endpoint will trigger webhooks for a sample job and send appropriate payloads to your specified URLs. You can test:
  • Job webhooks by providing a webhook_url
  • Tool webhooks by providing a tool_webhook_url
  • Filtered tool webhooks by also including tool_webhook_ids
A successful test will return:
This allows you to verify your webhook implementation before processing real job events.

Best Practices

  1. Always verify the HMAC signature to ensure the authenticity of webhook payloads.
  2. Implement proper error handling and retries in your webhook receiver to manage potential network issues or service interruptions.
  3. Process webhook payloads asynchronously to avoid blocking your webhook receiver.
  4. Store the raw payload for debugging purposes before processing it.
  5. Respond quickly to the webhook request (ideally within a few seconds) to avoid timeouts.
  6. When using tool webhooks, be prepared to handle events in any order as different tools have different processing times.
  7. Consider implementing separate endpoints for job webhooks and tool webhooks to simplify processing logic.
By following these guidelines and using the provided testing tools, you can ensure a robust and secure webhook integration with the Parcha API.