Example Keygen Webhook Handler
The following web app is written in Node.js and shows how to set up a simple webhook handler for Keygen, allowing you to listen for and act upon particular events on your Keygen account.
This example application is not 100% production-ready, but it should get you 90% of the way there. You may need to add additional logging, error handling, validation, features, etc.
Running the app
First up, configure a few environment variables:
# Your Keygen account ID.
export KEYGEN_ACCOUNT_ID="YOUR_KEYGEN_ACCOUNT_ID"
# Your Keygen authentication token. This may be an admin token, or
# a product token, depending on how you prefer to set things up. An
# admin token will have access to events for all of your products,
# while a product token can only access events related to that
# particular product.
export KEYGEN_TOKEN="YOUR_KEYGEN_TOKEN"You can either run each line above within your terminal session before
starting the app, or you can add the above contents to your ~/.bashrc
file and then run source ~/.bashrc after saving the file.
Next, install dependencies with yarn:
yarn
Then start the app:
yarn start
Testing webhooks locally
For local development, create an ngrok tunnel:
ngrok http 8080
Next up, add the secure ngrok URL to your Keygen account to listen
for webhook events.
- Keygen: add
https://{YOUR_NGROK_URL}/keygento https://app.keygen.sh/webhook-endpoints
You can now create events within your Keygen account, e.g. create a new license, and the webhook event will be sent to your local server.
Questions?
Reach out at support@keygen.sh if you have any questions or concerns!