Skip to the content.

Express Webhook Endpoint Example

This is a webserver using NodeJS + Express which behaves as a webhook. It demonstrates how to receive and verify webhook events for a High Fidelity Spatial Audio App. Webhooks can monitor when users connect and disconnect from any spaces in an app.

Setting up the webserver

Notes on setting up the webserver for production

In order for a production webserver to receive webhook events, the server must be publicly accessible to the internet from the port that the server is running on, and the server must be reachable from a public IP address or domain name.

In order for webhook events to be sent to your production webserver, you will need:

How the webserver works, using some example data

Once you have learned how to set up the High Fidelity Webhook Endpoint Example on your local machine from the default port 8080, the steps below will show how to send an example webhook event to the webserver using curl. This curl command works when the WEBHOOK_SECRET in index.js is set to aaaaaaaa-1111-bbbb-2222-cccccccccccc (this is its initial value).

The example webhook event explained

The webhook event in the curl command example has two parts: the signature and the JSON payload.

This is the signature of the example webhook event, which appears as an HTTP header in the webhook event:

X-HighFidelity-Signature: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..XG_FvBwdqUS9TCTdZBT0htvEeUsuLmwWFwjVPdJdFBI

In index.js, the function parseAndValidateWebhookEvent is used to compare this signature with the JSON payload, using the WEBHOOK_SECRET. This signature is a JWT (JSON Web Token) with the base4url-encoded payload removed from the middle, in favor of the JSON payload.

This is the JSON payload, which appears in the request body of the webhook event:

{
  "event-type": "connection-change",
  "iat": 1629237185,
  "exp": 1660773185,
  "space-id": "ace3c85a-703b-6cb4-e541-2a140f9087cd",
  "connected-user-count": 1,
  "connection-changes": [
    {
      "visit-id-hash": "riH6LPNViJxfGSQ8z37wAf5yYJmuRiReeAAaMO92S1j=",
      "jwt-user-id": "",
      "new-connection-state": "connected"
    }
  ]
}

This particular webhook event is for the first user connecting to a space. Here are the meanings of its fields (“claims” in JWT jargon):

Author

Sabrina Shanman