1. Expose a Subscriber Endpoint
To receive notifications on changes in resource status, you must expose a publicly accessible subscriber endpoint on your side. The endpoint must handle bothHEAD and POST requests over HTTPS.
To quickly expose an endpoint for testing, we will use
webhook.site in this guide, which allows you to easily
inspect, test and automate any incoming HTTPS request or e-mail directly in a
web browser.
When visiting webhook.site for the first time, you
should see a status message that looks like the following:
Your unique URL (Please copy it from here, not from the address bar!)
https://webhook.site/83fa21a0-f00a-4673-bb50-bcf62c78b1f7Record the value of the unique URL.In the example above, the unique URL
is:
https://webhook.site/83fa21a0-f00a-4673-bb50-bcf62c78b1f7. Use the
public-facing URL you receive as you progress throughout this guide.2. Subscribe to Webhook Notifications
Now that you have a publicly accessible endpoint, you need to register your endpoint as a subscriber to webhook notifications by doing the following:- Click Webhooks in your Circle Developer account.
- Click Add a Webhook in the upper right corner.
- Enter your endpoint URL from above. It will be similar to the earlier
example:
https://webhook.site/83fa21a0-f00a-4673-bb50-bcf62c78b1f7. - Click Add Webhook.
- At this stage, you should receive a Hello World test notification indicating you have subscribed to your endpoint successfully:
JSON
Customize Webhook Notifications
You can customize your webhook notifications. Customized webhook notifications allow you to listen to a restricted set of specific events, such as inbound transactions only, or a specific set of events, such as transaction or challenges, through a URL endpoint on your receiving application. To customize your endpoints to only receive certain notifications, toggle on “Limit to specific events” when creating your webhook. You are then able to pick the event categories that you want to listen to on your endpoint. These can be further customized at the event level under each category. This gives you the flexibility to only listen to events you care about at each endpoint, rather than overwhelming the endpoint with all notifications. This reduces the amount of data your server needs to process, making it more efficient and easier to manage. It also helps in focusing only on the relevant events, which can improve the performance and reliability of your application.3. Initiate a Challenge Flow to Receive a Notification
To observe a notification message on the status of a challenge, initiate the creation of a wallet (for example, by following the user-controlled wallets interactive quickstart for creating a user-controlled wallet). Once you successfully initiate a challenge payment, you should see a notification message on your local server shell that looks like the following: Sample Challenge Notification:JSON
4. Verify Digital Signature
- Every webhook notification is digitally signed by an asymmetric key. In the
headers of each webhook, you can find:
X-Circle-Signature: a header containing the digital signature generated by CircleX-Circle-Key-Id: a header containing the UUID you need to retrieve the relevant public key
- Using the X-Circle-Key-Id value, query the following endpoint to retrieve the
public key and algorithm used to sign the message:
GET /v2/notifications/publicKey/{keyId)
Shell
Response Body
- Use the public key and algorithm to verify the integrity of the webhook’s
payload against the signature found in
X-Circle-Signature.
Response Body
X-Circle-Signature:
5. Confirm IP Accesslist
To ensure the security of your integration, only trust Circle webhook notifications from the following IP addresses.54.243.112.156100.24.191.3554.165.52.24854.87.106.46
Webhook notification handlingWe enforce a 5 second timeout for your endpoint to respond back to our webhook
notifications. It is highly recommended that you process notifications outside
of the response loop and respond back promptly.