Webhooks
A webhook is a callback function that delivers an event payload to a URL when certain events occur in Nitro. The URL can be any address, including https, where you can access the files sent by Nitro. Typically, webhook data is used to develop processes not available in Nitro. For example, you could create a process that ingests the webhook data to send an email notification when a user receives a recognition.
You can trigger a webhook when the following events occur:
- Points earned - Data includes the user ID, point category, number of points, time when the points were awarded, and other event information.
- Mission completion - Data includes the earned user's ID and name, the completion timestamp, and the mission ID, name, display name, action phrase, point rewards and other mission information.
- Level earned - Data includes the earned user's ID and first and last name, the level name and description, if the user leveled up or down, and other information.
- Recognition given - Data includes the exchange ID and name, the giver's ID and name, the recipient's ID and name, the category ID and name, and other recognition information.
Create or Edit a Webhook
- Open Nitro Studio > Integrate > Webhooks.
- Click New. Or, to edit an existing webhook, click Edit ().
- Set webhook properties:
- User mission complete - send the payload when a user completes a mission. A payload will not be sent for group mission completions.
- User [point category name] earned - send the payload when a user earns points within this point category.
- [interaction name] interaction created - send the payload when a user gives a recognition within this recognition exchange.
- User level earned - send the payload when a user's level changes.
- Click Save.
- (Recommended) Add code to validate the authenticity of the request you receive from Nitro using the information in the Webhook URL Validation section.
Field |
Description |
---|---|
Name |
The webhook name. |
Description |
The webhook description. |
Callback Url |
The URL of the location where you want to receive the event payload. |
Active |
Select to activate the webhook. |
Triggers |
Select an event trigger. When an event occurs for the webhook type, an event payload will be sent to the Callback URL. Each point category can only be associated with one webhook. The available triggers are: |
Webhook Processing
A webhook eventId is unique to the payload event. If a webhook call fails (the HTTP status code returned to Nitro is not between 200 and 399), it's retried every 3 hours up to 3 days. The original and retry calls are identical in terms of payload, headers, etc.
When sending a response to Nitro after receiving a payload, the response should be sent as soon as the payload is received as the endpoint timeout is 30 seconds.
Webhook URL Validation
The event payload will be delivered in UTF-8 format via a POST call to the URL configured in the webhook.
Show me an example of the body of a points event post call
Show me an example of the body of a mission completion event post call
Show me an example of the body of a level earned event post call
Show me an example of the body of a recognition event post call
Once you define the URL, you can validate the authenticity of the request from Nitro. The following authorization headers are provided in the http call:
- Authorization - SHA256 Signature=<authorization signed hash>
- x-bb-content-sha256 - The event in the body, hashed into a sha256 string
- x-bb-date - A UNIX timestamp generated at the moment the event was sent
You will need your site's secret key to complete the following verification steps. The secret key is available in Nitro Studio > Configuration > Site Settings > Overview > API secret key.
- Concatenate the following strings into one.
<your site's secret key> "|" <x-bb-content-sha256 header value> "|"<x-bb-date header value>
- Convert the string from Step 1 into a SHA256 hash. The hash must be 64 characters long. If your hash is shorter than 64 characters, prefix the hash with zeros to make it 64 characters.
<your language of choice string to sha256 converter>(<string from step 1>)
- Compare the hash produced in Step 2, with the hash in the Authorization header (with the “SHA256 Signature=” prefix removed).
<hash from step 2> == <authorization signed hash - without the “SHA256 Signature=” part from the Authorization header>
- Convert the entire event body payload received into a SHA256 hash. The hash must be 64 characters long. If your hash is shorter than 64 characters, prefix the hash with zeros to make it 64 characters.
Ensure the hash contains the raw payload and with no formatting applied to the data. Formatting may cause you to lose the numeric precision that the original content was generated with.
<your language of choice string to sha256 converter>(<event body received>)
- Compare the hash produced in Step 4 with the hash received in the x-bb-content-sha256 header.
<hash from step 4> == <x-bb-content-sha256>
If the comparisons in Step 3 and Step 5 pass, your payload is guaranteed to originate from Nitro.
Show me example code I can modify to use for validation
See also