POST.
A webhook belongs to an organization. It sends the events of every product in the organization, including products added later, or only the products you choose.
Event types and the shape of each event’s data only grow. Keys can be added. They are not renamed or removed without a new event type. Write your receiver to ignore keys it does not know.
Requirements
- NervesHub 2.5.0 or later.
- The built-in Manage or Admin role, or a custom role with the webhook permissions (Add webhooks, Edit webhooks, Delete webhooks). See Roles.
- An endpoint on a public address. An instance only delivers to private or loopback addresses when its operator sets
WEBHOOKS_ALLOW_PRIVATE_DESTINATIONS=true. See Feature prerequisites. - Some events need an extension or an instance feature before they fire. See Events.
Add a webhook
1
Open the Integrations page
Open your organization and select the Integrations tab.
2
Start a new webhook
Click Add webhook. Once the organization has any integration, click Add integration, then Webhook.
3
Fill in the form
Enter the URL of your endpoint. Optionally enter a Name. Without one, the list shows the URL’s host. Choose the products and the events, then click Add webhook.
4
Copy the signing secret
Open the webhook’s row menu and choose Copy signing secret. Give the secret to your receiver so it can verify deliveries.
Check that it works
Choose Send test event from the webhook’s row menu. NervesHub sends awebhook.test event to that webhook straight away and shows how your endpoint answered. The test is sent whether or not the webhook is on. Its result is not recorded against the webhook.
Delivery format
Each event is aPOST with a JSON body:
timestamp is when NervesHub raised the event, not when the delivery was sent. Every event carries org. Every event about a product carries product, and every event about a device carries device, so one endpoint can serve several products.
The headers follow the Standard Webhooks specification:
Answer with any
2xx status to accept a delivery. NervesHub reads only the status and ignores the response body. Answer quickly and do the work afterwards. A delivery that is not answered within 15 seconds counts as failed.
An event whose encoded body is larger than 256 KB is dropped and not delivered.
Verify signatures
Each webhook has its own signing secret. It iswhsec_ followed by 32 random bytes in base64.
The signature is the HMAC-SHA256 of the string below, keyed with the base64-decoded part of the secret after whsec_:
- Python
- JavaScript
- Python, no library
webhook-timestamp is within a few minutes of your clock. Compute the signature over the raw body. Compare it with each space-separated entry in webhook-signature using a constant-time comparison.
New signing secret… replaces the secret. The old secret stops working at once, including for retries of earlier events, so update your receiver straight away.
Retries, ordering and duplicates
A delivery fails when the status is outside2xx, the request times out, or the connection fails. NervesHub retries a failed delivery after about 5 seconds, 1 minute, 5 minutes, 30 minutes and 2 hours. After the sixth attempt it drops the delivery.
Redirects are not followed. A 3xx counts as a failure. Change the webhook’s URL instead.
Deliveries are at least once and unordered. A retry can arrive after a later event, and an event can be delivered twice. Use webhook-id to discard duplicates and timestamp to order events.
Each attempt reads the webhook as it is at that moment. A retry goes to the current URL and is signed with the current secret.
When an endpoint keeps failing
While an endpoint is failing, the Integrations page shows when it started failing and the latest error. For 30 seconds after a failure, NervesHub does not send that webhook’s other deliveries. Each one counts as a failed attempt and is retried on the schedule above. NervesHub turns a webhook off when its endpoint:- has accepted no delivery for 24 hours, or
- answers
410 Gone.
Where a webhook can point
The URL must start withhttps:// or http:// and must not include a username or password. Use https://. The signature proves where a delivery came from. It does not hide the contents.
By default a webhook can only reach public addresses. NervesHub refuses loopback, private, link-local and other reserved addresses:
- A URL with a literal private address is refused when you save the webhook.
- A host name is resolved at delivery time. The delivery fails if any address it resolves to is private or reserved.
WEBHOOKS_ALLOW_PRIVATE_DESTINATIONS=true. See Feature prerequisites.
Events
A webhook subscribes to any of these types.webhook.test is only sent on request.
An extension must be on for the product and for the device. A product created through the API or
nh starts with every extension off, so check Product settings before expecting an extension’s events. See Extensions overview. For the instance side, see Feature prerequisites.
The device
Every device event’sdata.device identifies the device and the firmware it is running, as far as NervesHub knows:
firmware is null for a device that has never reported its firmware. The examples below leave out device, org and product.
device.connected
connection.id is the same in the matching device.disconnected.
device.disconnected
reason_code says why the connection ended when NervesHub knows, and is null when it does not. Match on reason_code. reason is the same thing written for people and can be reworded.
expected_wake_at is when a device that went to sleep said it would be back. It is null otherwise, including for a sleeping device that gave no time.
Devices that sleep are on the main branch but in no tagged release as of
nerves_hub_link 2.14.0 and NervesHub 2.5.4. See Sleeping devices.device.health_reported
metrics holds the readings NervesHub stored. Only numbers are kept. alarms and metadata are passed on as the device sent them.
device.metrics_reported
timestamp is when the device took the readings. Reports NervesHub did not store are left out. A batch with no stored report sends no event.
device.health_status_changed
status and previous_status are each one of unknown, healthy, warning or unhealthy. previous_status is null the first time a device is judged.
reasons names each metric holding the device at warning or unhealthy. It is null when nothing is engaged.
On an instance without ClickHouse, or for a product without a health profile, NervesHub judges a device on its latest report alone.
The event is sent only when the status changes. A device that stays at warning while the metric holding it there changes sends nothing.
device.firmware_update.scheduled
initiated_by is "deployment_group", "user" for an update a person sent from NervesHub, or "device" for a device that manages its own updates and asked for one. deployment_group is null when no deployment group is involved.
device.firmware_update.progress
status is one of received, started, downloading, updating or completed. completed means the firmware is installed and the device is about to restart into it. The update has not finished until the device comes back on the new firmware.
progress is a percentage for downloading and updating, and null otherwise. While a device downloads or updates, an event is sent when the stage changes and then at most every 15 seconds.
device.firmware_update.finished
reason is whatever the device said, if anything. source_firmware, target_firmware and deployment_group are null when not known. A firmware’s version is null once the firmware has been deleted.
device.firmware_validated
The event carries nothing beyond device.
error_group.created and error_group.reopened
These events are about an error, not one device. They carry org, product and error, and no device:
id is the error’s id in NervesHub and is the same in every event about it. occurrence_count is how many times the error has happened across the product’s devices so far. top_frame is null when the device sent no stack frames. reason is what the device said, so treat it as untrusted text.
A muted error does not reopen, so it sends neither event.
Deployment workflow events
These events are about a deployment group, not one device. They carryorg, product and the workflow, and no device:
workflow.stepsis how many steps the release’s workflow has.step.typeisupdate_devices,approval_requiredorcatch_all.catch_allis the last step.step.statusis the step’s status after it moved:in_progress,completed,errororskipped.useris who retried, approved or skipped the step, as{"name": ...}. It isnullwhen the workflow moved on its own.failed_devicesis set only onfailed.
awaiting_approval in place of started.
webhook.test
Sent only by Send test event or the API’s test endpoint, to the one webhook being tested. It carries org and no product or device:
Manage webhooks with the API
The API manages the same webhooks under/api/orgs/{org_name}/webhooks. Authenticate as described in API authentication.
Every endpoint needs permission to change webhooks, reading included, because a webhook’s URL can carry the receiver’s credentials. Listing, getting, updating, testing and regenerating need Edit webhooks. Creating needs Add webhooks. Deleting needs Delete webhooks. The built-in Manage and Admin roles have all three.
Create a webhook:
data. Products are named, as in the rest of the API.
- A webhook with
"all_products": true, the default, sends every product’s events, including products added later. - Naming products in
productssetsall_productstofalseunless the request says otherwise. productsin a response is empty for a webhook that sends every product’s events.
secret only by POST /webhooks and regenerate_secret. If you lose the secret, regenerate it.
The full request and response schemas are in your instance’s API documentation at /api/docs, under Webhooks.
With the CLI
Thenh CLI wraps the same endpoints:
nh webhook create prints the signing secret once. Save it then.

