OPX uses webhooks to notify your application when important events happen on your worksites. Instead of polling our API for changes, you receive an HTTP POST request as soon as an event occurs.
Setup
Creating a webhook
Webhooks are managed directly in OPX, under Settings › Developers › Webhooks (this requires the permission to manage the developer space). For each webhook, you provide:
- URL: the HTTPS endpoint that will receive the notifications.
- Events: at least one of the available events. A webhook only receives the events it is subscribed to.
- Secret (optional, 16 characters minimum): used to sign every notification. If you leave it empty, OPX generates one for you.
The secret is displayed only once, right after the webhook is created. Store it securely: it cannot be displayed again.
You can create several webhooks, for instance to send different events to different endpoints.
Connectivity check
When a webhook is created, OPX sends a single test request to its URL to check that it is reachable:
This request is not signed: at this point, your endpoint may not know the secret yet (especially if it was generated by OPX). Your endpoint should answer it with a 2XX status code without checking the signature. If it does not, the webhook is still created, but OPX warns that the URL could not be reached.
Every notification shares the same envelope:
Available events
Status changed worksite_status_changed
Triggered when a worksite moves forward to a new status. No notification is sent when a worksite goes back to a previous status, nor when it is deleted or cancelled.
status_id is sent as a string.
Possible statuses, in workflow order:
Operation updated worksite_operation_updated
Triggered when an operation of a worksite is updated. Several changes made to the same operation in a single action are grouped into one notification.
The payload only identifies the operation: use the API to retrieve its current data.
Operation custom status changed worksite_operation_custom_status_changed
Triggered when a custom status is applied to an operation. Only webhooks of the entity that owns this custom status receive this event.
The payload does not include the new custom status: use the API to retrieve it.
Document generated worksite_document_generated
Triggered when a new document is generated for a worksite.
Documents controlled worksite_documents_controlled
Triggered when all documents of a worksite have been reviewed and validated.
Receiving webhooks
To receive webhooks correctly, your endpoint must:
- Verify the authenticity of each notification using the
Signature header (see Security).
- Respond quickly, within 3 seconds, with a 2XX status code. Any other final response, or a timeout, counts as a failure.
- Process asynchronously any logic that takes longer.
- Ignore duplicates using
event_id: a notification can be delivered more than once.
Security
Each notification includes a Signature header, which lets you verify that the request was sent by OPX and was not altered in transit. The only exception is the connectivity check, which is not signed.
The signature is the HMAC-SHA256 of the raw request body, computed with your secret and encoded in lowercase hexadecimal, with no prefix.
PHP:
Java:
Retry strategy
If your endpoint does not respond within 3 seconds, or responds with a non-2XX status code, OPX retries the delivery. Each notification is attempted 3 times in total:
- 1st attempt: immediately;
- 2nd attempt: 10 seconds after the first failure;
- 3rd attempt: 100 seconds after the second failure.
After the third failed attempt, the notification is dropped.