Webhooks & Notifications¶
When running batch processes on the SCo2-API, it is important to be able to track the progress of the process and be notified when it is completed. This is where webhooks and notifications come in.
Webhooks¶
Webhooks are a way for an app to provide other applications with real-time information.
Endpoints¶
The webhook system provides the following endpoints:
POST /webhooks/register: Register a webhook URL to receive notificationsDELETE /webhooks/remove: Remove the registered webhookPOST /webhooks/test: Send a test webhook to verify your webhook server is working
Register a Webhook¶
Register a webhook to receive notifications when batch processes are completed. You can only register one webhook address per user.
Important:
- Only one webhook address can be registered per user
- The webhook address must be a valid HTTPS URL (HTTP allowed only in development with emulators)
- You will receive a client_secret that you must store securely for webhook signature validation
- You cannot choose which events to receive - you will receive all webhook notifications
Python¶
JavaScript¶
cURL¶
Remove a Webhook¶
To remove your registered webhook:
| remove_webhook.py | |
|---|---|
Test a Webhook¶
To send a test webhook to verify your webhook server is working:
| test_webhook.py | |
|---|---|
Webhook Events¶
Currently, the following webhook event types are supported:
batch_zonal_stats_complete: Sent when a batch zonal statistics operation completestest_event: Sent when using the/webhooks/testendpoint
Receiving Webhooks¶
When a batch process is completed, you will receive a POST request at your registered webhook URL.
Webhook Headers¶
Each webhook request includes the following headers:
| Header | Description |
|---|---|
Host |
The host of the API (api.epoch.com) |
User-Agent |
Epoch-Webhooks/1.0 |
Content-Type |
application/json |
X-Epoch-Webhook-Type |
The event type that triggered the webhook (e.g., batch_zonal_stats_complete) |
X-Epoch-Webhook-Signature |
The HMAC SHA256 signature for validating the webhook (format: t={timestamp}, v1={signature}) |
Webhook Payload¶
The webhook body contains the following structure:
{
"id": "ec26f2760191469fbd7920bef6729cba",
"type": "batch_zonal_stats_complete",
"data": {
"collection_name": "brazil_pasture",
"description": "brazil_pasture",
"urls": {
"biomass_emissions": "https://epoch-sco2-api.com/fetch_biomass_emissions?filename=0x102dfff79ed1477398b5cf1360730fbf20676b2cb5dbc7841f9c27ec808d12c2&monitoring_start=2017-01-01&monitoring_end=2024-09-18",
"biodiversity": "https://epoch-sco2-api.com/fetch_biodiversity?filename=0x102dfff79ed1477398b5cf1360730fbf20676b2cb5dbc7841f9c27ec808d12c2&monitoring_start=2017-01-01&monitoring_end=2024-09-18",
"deforestation_check": "https://epoch-sco2-api.com/fetch_deforestation_check?filename=0x102dfff79ed1477398b5cf1360730fbf20676b2cb5dbc7841f9c27ec808d12c2&monitoring_start=2017-01-01&monitoring_end=2024-09-18",
"deforestation_check_eudr": "https://epoch-sco2-api.com/fetch_deforestation_check?filename=0x102dfff79ed1477398b5cf1360730fbf20676b2cb5dbc7841f9c27ec808d12c2&monitoring_start=2021-01-01&monitoring_end=2024-09-18",
"export_eudr_dds": "https://epoch-sco2-api.com/export_eudr_dds?filename=0x102dfff79ed1477398b5cf1360730fbf20676b2cb5dbc7841f9c27ec808d12c2&monitoring_start=2021-01-01&monitoring_end=2024-09-18"
}
},
"created_at": "2024-09-18T15:48:06.515699"
}
Payload Fields¶
| Field | Type | Description |
|---|---|---|
id |
string | Unique identifier for the webhook event (use for deduplication) |
type |
string | The event type (same as X-Epoch-Webhook-Type header) |
data |
object | Event-specific data containing collection information and fetch URLs |
created_at |
string | ISO 8601 timestamp of when the webhook was created (not the send time, due to possible retries) |
Using Fetch URLs¶
The urls object in the webhook payload contains pre-formatted URLs to fetch the processed data. When using these URLs, you must include your Bearer token in the Authorization header. The data returned is a streaming response - see the Fetch API documentation for more information.
Webhook Security¶
Signature Validation¶
All webhooks include an HMAC SHA256 signature in the X-Epoch-Webhook-Signature header. You must validate this signature to ensure the webhook was sent by Epoch and not a malicious actor.
The signature format is: t={timestamp}, v1={signature}
Where:
- t is a Unix timestamp of when the webhook was signed
- v1 is the HMAC SHA256 signature of the payload
Validation Example (Python)¶
Validation Example (JavaScript)¶
Best Practices¶
- Always validate the signature using the
client_secretyou received during registration - Store the
client_secretsecurely - never expose it in client-side code or logs - Use the
idfield to deduplicate webhook events (webhooks may be retried) - Return HTTP 200 quickly - process the webhook asynchronously if needed
- IP address restrictions (optional): Consider restricting your webhook endpoint to only accept requests from Epoch's IP addresses (contact support for IP ranges)
Retry Logic¶
If a webhook fails to send (non-200 response), the system will automatically retry up to 3 times with exponential backoff:
- First retry: After 10 seconds
- Second retry: After 30 seconds
- Third retry: After 60 seconds
After all retries are exhausted, the webhook delivery is considered failed. Ensure your webhook endpoint returns HTTP 200 quickly to avoid unnecessary retries.
Email Notifications¶
While webhooks are ideal for receiving notifications about data availability with pre-formatted endpoints to fetch it,
Epoch also enabled Email notifications for users who want to receive the EUDR DDS reports directly in their inbox.
To enable email notifications for the EUDR DDS, you need to set the eudr_dds boolean to True as part of the
request parameters for the batch process.