Events
Events notify you when important actions happen inside an organization.
For example, Polytomic emits a sync.completed event every time a sync
finishes.
You can consume events in two ways:
- Poll the events endpoint.
- Register a webhook to receive events in real time.
⚠️ At-most-once delivery
Polytomic delivers each event at most once and does not re-send events after delivery. If you need guaranteed processing of every change, build a fallback that polls the events endpoint in addition to consuming the webhook.
Polytomic retains events for 48 hours. After that they are no longer available from the events endpoint.
Event types
The event types are as follows:
sync.runningsync.failedsync.canceledsync.completedsync.completed_with_errorsbulk_sync.runningbulk_sync.completedbulk_sync.canceledbulk_sync.failedbulk_sync.completed_with_error
Webhooks
Create and manage webhooks through the webhook API. A webhook fires events for the organization it belongs to. Each organization can have one webhook.
Each delivery is an HTTP POST with a JSON body. The top-level id is the
event’s UUID and stays the same across delivery attempts. The top-level
created_at is the event creation time in UTC, in RFC 3339 format. The
type names the event, and event contains its type-specific fields.
Verify webhook signatures
When you create or update a webhook, you supply a secret. Polytomic sends
these headers with each delivery:
To verify webhook-signature, compute HMAC-SHA256 with the UTF-8 bytes of
your webhook secret as the key. Sign the following bytes, using the
unmodified request body:
Decode the base64 value after v1, and compare the digests in constant
time. Check that the timestamp falls within a freshness window suitable
for your endpoint before processing the event. Also check that the body
id matches webhook-id. Use that ID to recognize repeat attempts;
the timestamp and signature can differ for the same event.
Polytomic also sends Polytomic-Signature for existing consumers. Its value
is the lowercase hex-encoded HMAC-SHA256 of the raw request body, using
the same secret. You can continue verifying this header while migrating to
webhook-signature.
Delivery
Your endpoint must return a 2xx status code. If it does not, Polytomic
retries the delivery up to five times with exponential backoff. Event ordering
is not guaranteed.
Record logs
The sync.completed event payload (see the example below) includes
links to JSON logs of the records Polytomic inserted or updated. See the
total_records, inserted_records, and updated_records fields.
Event payload examples
Consuming events
The following Go example verifies a delivery’s signature, timestamp, and
event ID before accepting it. Replace somepassword with your webhook
secret and process the event after verification.
