Skip to content

Webhooks Endpoints — Admin API

Granit.Webhooks.Endpoints exposes a Minimal API for managing webhook subscriptions: create and update subscriptions, transition through lifecycle states (active, suspended, deactivated), rotate signing secrets, send test pings, and monitor delivery statistics. All endpoints are protected by the Webhooks.Admin authorization policy with configurable role requirements.

  • DirectoryGranit.Webhooks.Endpoints/ Minimal API route groups + DTOs + validators
    • Granit.Webhooks Core abstractions (IWebhookSubscriptionReader/Writer)
    • Granit.Webhooks.EntityFrameworkCore EF Core persistence + IWebhookQueryableProvider
// In your application startup
app.MapWebhooksEndpoints();
// With custom options:
app.MapWebhooksEndpoints(opts =>
{
opts.RoutePrefix = "admin/webhooks";
opts.RequiredRole = "platform-admin";
opts.TagName = "Webhook Administration";
});
OptionDefaultDescription
RoutePrefix"webhooks"Route prefix for all webhook endpoints
RequiredRole"granit-webhooks-admin"Role required for the authorization policy
TagName"Webhooks"OpenAPI tag name for endpoint grouping

Configuration section: WebhooksEndpoints.

MethodRouteDescription
GET/event-typesList all registered webhook event types

Returns the full list of event types declared by application modules via IWebhookEventTypeDefinitionProvider. Each entry includes the event type name, localized display name, description, and category for UI grouping. Labels are resolved based on the Accept-Language header. Requires Webhooks.Subscriptions.Read permission.

MethodRouteDescription
GET/subscriptions/{id}Get a webhook subscription by ID
MethodRouteDescription
POST/subscriptionsCreate a new subscription (returns signing secret once)
PUT/subscriptions/{id}Update a subscription’s target URL
DELETE/subscriptions/{id}Hard-delete a subscription
MethodRouteDescription
POST/subscriptions/{id}/activateReactivate a suspended subscription
POST/subscriptions/{id}/suspendSuspend an active subscription
POST/subscriptions/{id}/deactivatePermanently deactivate a subscription
stateDiagram-v2
    [*] --> Active: Create
    Active --> Suspended: Suspend
    Suspended --> Active: Activate
    Active --> Deactivated: Deactivate
    Suspended --> Deactivated: Deactivate
MethodRouteDescription
POST/subscriptions/{id}/rotate-secretRotate the HMAC signing secret
POST/subscriptions/{id}/test-pingSend a Stripe-style test ping to the target URL
GET/statsGet aggregate delivery statistics (last 24h)

When Granit.Webhooks.EntityFrameworkCore is registered, query endpoints are available:

MethodRouteDescription
POST/subscriptions/queryFilter, sort, and paginate subscriptions
POST/deliveries/queryFilter, sort, and paginate delivery attempts
DTODirectionUsed by
WebhookEventTypeResponseOutputGET event-types
WebhookSubscriptionCreateRequestInputPOST subscriptions
WebhookSubscriptionCreatedResponseOutputPOST subscriptions (includes signing secret)
WebhookSubscriptionUpdateRequestInputPUT subscriptions
WebhookSubscriptionDeactivateRequestInputPOST deactivate
WebhookSubscriptionResponseOutputGET, PUT, lifecycle endpoints
WebhookSubscriptionRotateSecretResponseOutputPOST rotate-secret
WebhookSubscriptionTestPingResponseOutputPOST test-ping
WebhookSubscriptionStatsResponseOutputGET stats

All endpoints require the Webhooks.Admin authorization policy. Permissions are defined in WebhooksPermissions:

PermissionDescription
Webhooks.Subscriptions.ReadView subscriptions, list event types
Webhooks.Subscriptions.ManageCreate, update, delete, lifecycle transitions, rotate secrets, test pings, stats

All request DTOs are automatically validated via FluentValidation through MapGranitGroup(). Key rules:

  • Target URL: HTTPS only, absolute URI, max 2048 chars
  • SSRF protection: blocks private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16), localhost, link-local IPv6, and blocked TLDs (.local, .internal, .onion)
  • Event type: non-empty, max 200 chars, must exist in the event type registry
  • Deactivation reason: non-empty, max 1000 chars
  • Webhooks — core module documentation (publisher, delivery engine, retry)