Webhooks
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:
- Job Webhooks (
webhook_url
): Receive notifications when the entire job is completed - 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 the final job results:
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:
- Text extraction results (fastest)
- Visual verification
- 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 documentbusiness_name
: The primary name of the businessall_business_names
: Array of all business names found in the documentincorporation_date
: The date of incorporationbusiness_address
: The primary business addressall_extracted_addresses
: Object containing all addresses found in the document, categorized by typebusiness_activity
: The stated purpose or activity of the businessjurisdiction
: The jurisdiction where the business is incorporatedbusiness_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 an HMAC-SHA256 signature. This signature is included in the X-Signature-SHA256
header of the webhook request.
To verify the signature:
- Compute the HMAC-SHA256 signature of the raw request body using your API secret key.
- 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:
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
- Always verify the HMAC signature to ensure the authenticity of webhook payloads.
- Implement proper error handling and retries in your webhook receiver to manage potential network issues or service interruptions.
- Process webhook payloads asynchronously to avoid blocking your webhook receiver.
- Store the raw payload for debugging purposes before processing it.
- Respond quickly to the webhook request (ideally within a few seconds) to avoid timeouts.
- When using tool webhooks, be prepared to handle events in any order as different tools have different processing times.
- 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.