Introduction
Retab uses HTTPS to send webhook events to your app as a JSON payload representing aWebhookRequest
object.
You will need a server with a webhook endpoint that will receive the webhook_request
payload, allowing you to process them as you want after that.
- Create a new processor with your extraction configuration.
- Create a webhook endpoint handler to receive event data POST requests.
- Create a new automation sending data to your webhook endpoint.
- Test your webhook endpoint handler locally using the Retab SDK.
- Secure your webhook endpoint.
Create your processor
Start by creating a processor with your extraction configuration.Create your FastAPI server with a webhook
Then, set up a FastAPI route that will handle incoming webhook POST requests. You will need it to create an automation. Below is an example of a simple FastAPI application with a webhook endpoint:Secure your webhook endpoint
When you set up a webhook, you provide an HTTP endpoint on your server for Retab to send data to. If this endpoint is not secured (i.e., it accepts unauthenticatedPOST
requests from anywhere), it essentially becomes a public door into your system. Any actor could attempt to call this URL and send fake data. This is inherently dangerous: a malicious party might send forged webhook requests that masquerade as Retab, but contain bogus or harmful data.
To secure webhook deliveries, Retab employs a signature verification mechanism using an HMAC-like scheme. Retab and your application share a webhook secret (a random string known only to Retab and you). This secret is available in your Retab dashboard (Labeled as WEBHOOKS_SECRET
). Retab uses this secret to include a special signature header with every webhook request. When your endpoint receives the webhook, your code should perform the same HMAC-SHA256 computation on the request body using the shared secret, then compare your computed signature to the value in the Retab-Signature
header. If the signatures match, the request truly came from Retab and the payload was not altered in transit.
Make sure to set your
WEBHOOKS_SECRET
environment variable with the secret from your Retab dashboard.Exposing local server to the internet using ngrok
We have a very simple Dockerfile that fastapi+ngrok to get you started.
Check out the webhook_server folder for more details.
You will need a ngrok auth token to run the docker container. You can get one here
webhook URL
, you will need it on the next steps.
Create an automation
Now, you can create an automation that will use your processor to extract data from emails.invoices@mailbox.retab.com
, the automation will use your processor configuration to extract data and send a POST request to your FastAPI webhook endpoint.
You can see the processor and automation you just created on your dashboard!
Test your automation
Finally, you can test the processor and automation rapidly with the test functions of the SDK:You can also test your webhook locally by overriding the webhook url set in the automation
That’s it! You can start processing documents at scale.