Configure organization webhooks in Konnect

Incompatible with
on-prem
Related Documentation
TL;DR

Create an HTTP destination, save its signing secret, then create an organization subscription for an event and destination. This tutorial shows how to create a webhook to receive notifications when a new user registers in your Dev Portal.

Prerequisites

If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. The following Konnect items are required to complete this tutorial:
    • Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
  2. Set the personal access token as an environment variable:

    export KONNECT_TOKEN='YOUR KONNECT TOKEN'

You need an organization administrator role to manage notification destinations and subscriptions.

Prepare a publicly resolvable HTTPS endpoint that can receive POST requests from Konnect.

  • You can generate a URL by navigating to https://webhook.site and copying the free URL.
  • Set the endpoint URL as an environment variable:

      export WEBHOOK_URL='YOUR URL'

For this tutorial, you’ll need a Dev Portal and some Dev Portal settings pre-configured. These settings are essential for Dev Portal to function but configuring them isn’t the focus of this guide. If you don’t have these settings already configured, follow these steps to pre-configure them:

  1. Create a Dev Portal:

    curl -X POST "https://us.api.konghq.com/v3/portals" \
         --no-progress-meter --fail-with-body  \
         -H "Authorization: Bearer $KONNECT_TOKEN" \
         --json '{
           "name": "MyDevPortal",
           "authentication_enabled": true,
           "auto_approve_applications": true,
           "auto_approve_developers": true,
           "default_api_visibility": "public",
           "default_page_visibility": "public"
         }'
  2. Export your Dev Portal ID and URL from the output:

    export PORTAL_ID='YOUR-DEV-PORTAL-ID'
    export PORTAL_URL='YOUR-DEV-PORTAL-DOMAIN'
  3. Create a page in your Dev Portal so published APIs will display:

    curl -X POST "https://us.api.konghq.com/v3/portals/$PORTAL_ID/pages" \
         --no-progress-meter --fail-with-body  \
         -H "Authorization: Bearer $KONNECT_TOKEN" \
         --json '{
           "title": "My Page",
           "slug": "/",
           "description": "A custom page about developer portals",
           "visibility": "public",
           "status": "published",
           "content": "# Welcome to My Dev Portal\nExplore the available APIs below:\n::apis-list\n---\npersist-page-number: true\ncta-text: \"View APIs\"\n---\n"
         }'

Organization webhooks send selected Konnect events to an HTTP endpoint. Destinations and subscriptions are managed at the organization level and are separate from user email and in-app notification preferences.

Organization webhooks aren’t limited to events in the organization namespace. Organization administrators can subscribe to events from other Konnect areas, such as Dev Portal, Kong Gateway, and Plan and Usage. This guide uses a Dev Portal event because you can trigger it on demand.

List available events

List the organization events that are available to your org. The response contains each event’s event_type, title, description, and namespace. Use the event_type as the event ID when creating a subscription.

curl -X GET "https://global.api.konghq.com/v1/notifications/configurations/organization" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

This tutorial uses the devportal_developer.registration_pending event.

Create an HTTP destination

Create a destination for the endpoint. You can add custom headers for credentials or routing; the Standard Webhooks and transport headers are reserved. An organization can have up to 50 destinations.

_response=$(curl -X POST "https://global.api.konghq.com/v1/notifications/destinations" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "name": "Production notifications",
       "type": "http",
       "url": "'$WEBHOOK_URL'",
       "custom_headers": {
         "X-Environment": "production"
       }
     }')

Export the env variables:

export DESTINATION_ID=$(echo "$_response" | jq -r ".id")
export SIGNING_SECRET=$(echo "$_response" | jq -r ".signing_secret")

The request captures the destination id and signing_secret from the response for the following steps. Store the signing secret securely so your receiver can verify that requests came from Konnect. The API returns the signing secret only when the destination is created.

Require approval for new developers

This guide uses the devportal_developer.registration_pending event, which Konnect sends when a developer signs up for a Dev Portal that requires approval. Turn off auto-approve for developers so that new sign-ups are pending and trigger the event:

curl -X PATCH "https://us.api.konghq.com/v3/portals/$PORTAL_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "auto_approve_developers": false
     }'

Subscribe a destination to an event

Create a subscription using an event_type from the available events response and the destination ID:

SUBSCRIPTION_ID=$(curl -X POST "https://global.api.konghq.com/v1/notifications/configurations/organization/devportal_developer.registration_pending/subscriptions" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "name": "Developer registration notifications",
       "destination_ids": [
         "'$DESTINATION_ID'"
       ],
       "regions": [
         "*"
       ],
       "entities": [
         "*"
       ],
       "enabled": true
     }' | jq -r ".id"
)

To subscribe to a different event, replace devportal_developer.registration_pending with an event type returned for your organization.

Use * to receive the event for all regions and entities when those filters apply. You can also limit a subscription to specific regions or entity IDs.

Some event types might not use region or entity filters; follow the API response and validation errors for the event you select.

Trigger an event

Send a test request to verify that the destination can receive notifications:

curl -X POST "https://global.api.konghq.com/v1/notifications/destinations/$DESTINATION_ID/test" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

Then trigger a real event:

  1. Run echo https://$PORTAL_URL and open the returned URL in a private browser window.
  2. Click Sign up and register a test developer account.
  3. On webhook.site, check that you received a POST request for the devportal_developer.registration_pending event.

Review delivery history

List the deliveries for your destination. Each delivery shows its event_type, status, and mode, which is test for the test request and live for real events. The request captures the ID of the most recent delivery:

DELIVERY_ID=$(curl -X GET "https://global.api.konghq.com/v1/notifications/deliveries?filter%5Bdestination_id%5D%5Beq%5D=$DESTINATION_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" | jq -r ".data[0].id"
)

Inspect the delivery and each of its attempts:

curl -X GET "https://global.api.konghq.com/v1/notifications/destinations/$DESTINATION_ID/deliveries/$DELIVERY_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

If a delivery has the failed status, you can resend it:

curl -X POST "https://global.api.konghq.com/v1/notifications/destinations/$DESTINATION_ID/deliveries/$DELIVERY_ID/resend" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

A resend has a new delivery ID but keeps the original event_id, which you can use to deduplicate event processing.

Requests include the Standard Webhooks webhook-id, webhook-timestamp, and webhook-signature headers. Verify signatures with the destination signing secret using the Standard Webhooks specification.

Pause notifications

To stop sending one event to its destinations without deleting the subscription, set enabled to false on the subscription:

curl -X PATCH "https://global.api.konghq.com/v1/notifications/configurations/organization/devportal_developer.registration_pending/subscriptions/$SUBSCRIPTION_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "enabled": false
     }'

To stop sending all events to a destination, set its state to disabled. Set it back to enabled to resume delivery:

curl -X PATCH "https://global.api.konghq.com/v1/notifications/destinations/$DESTINATION_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN" \
     --json '{
       "type": "http",
       "state": "disabled"
     }'

Deleting a destination removes it from all its subscriptions and deletes any subscription that has no destinations left.

Cleanup

Delete the subscription:

curl -X DELETE "https://global.api.konghq.com/v1/notifications/configurations/organization/devportal_developer.registration_pending/subscriptions/$SUBSCRIPTION_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

Delete the destination. This also deletes its signing keys and delivery history, and can’t be undone:

curl -X DELETE "https://global.api.konghq.com/v1/notifications/destinations/$DESTINATION_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

If you created a Dev Portal for this tutorial, delete it:

curl -X DELETE "https://us.api.konghq.com/v3/portals/$PORTAL_ID" \
     --no-progress-meter --fail-with-body  \
     -H "Authorization: Bearer $KONNECT_TOKEN"

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!