Skip to content

Webhook endpoints for your customers ​

Your customers (tenants) often want events in their own systems: a threshold reached, a user added, a role changed. Instead of building an endpoint manager, a signer, a retry loop and a delivery log yourself, let each tenant register its own endpoints with TenancyEngine. Deliveries use the same signing, retries and delivery log as your application webhooks.

All calls use an organization API key with the webhooks.manage scope, from your backend or your own settings page. The base path is /api/v1/runtime/tenants/{tenantId}/webhook-endpoints.

CallPurpose
GET /List the tenant's endpoints (including any that were switched off, and why).
POST /Create one. Body { "url": "https://...", "eventsCsv": "usage.threshold_reached,tenant.updated" }. The signing secret is in the response once (plainSecret).
PATCH /{id}Change url, eventsCsv or isActive. Turning an endpoint back on clears its failure state.
DELETE /{id}Remove it.
POST /{id}/rotate-secretNew secret; the old one keeps signing alongside it for graceHours (default 24) as v1_previous.
POST /{id}/testSend a webhook.test event now.
GET /{id}/deliveries?limit=50Delivery log: event, success, last status code, attempts. Response bodies are never returned.
POST /{id}/deliveries/{deliveryId}/redeliverSend a recorded delivery again, body unchanged.

What a tenant endpoint receives ​

Only events about its own tenant, and only these types: tenant.updated, tenant.deleted, user.invited, user.role_assigned, entitlement.changed, usage.near_limit, usage.at_limit, usage.threshold_reached, directory.user.created, directory.user.updated, directory.user.deactivated, directory.group.created, directory.group.updated, directory.group.deleted. Organization and application events, SMS, caching and automation events are yours and are never offered to a tenant. eventsCsv empty or * means all of the above.

Signing is exactly the scheme in Webhook events and redelivery, so one verifier serves your endpoints and your tenants'.

Safety rules ​

  • Tenant A cannot see, change or trigger tenant B's endpoints or log, and cannot reach your application-level endpoints. Another tenant's endpoint id answers 404.
  • URLs must be https, and destinations on private, loopback or link-local addresses are refused when you save and again when connecting.
  • A tenant may have 5 endpoints. They do not count against your application's 10.
  • If every delivery to a tenant endpoint has failed for 5 days, the endpoint is switched off (isActive: false, disabledReason: auto_disabled_after_sustained_failure) and the tenant's administrators are emailed under your application's name. Turn it back on with PATCH once it is fixed, then redeliver what was missed.

Give your customers a settings screen ​

@tenancyengine/react ships WebhookEndpointsPortal, a themed, accessible endpoint manager. It talks to a small proxy in your backend, because the routes above need your organization API key and a tenant id. The proxy must take the tenant id from the signed-in user's session, never from the request the browser sends; otherwise one customer could name another customer's tenant.

ts
// app/api/webhook-endpoints/[[...path]]/route.ts  (Next.js; the same shape works in any backend)
import { getSession } from '@/lib/session';

const RUNTIME = process.env.TE_BASE_URL + '/api/v1/runtime';

async function proxy(req: Request, { params }: { params: Promise<{ path?: string[] }> }) {
  const session = await getSession(req);
  if (!session?.tenantId || !session.canManageIntegrations) return new Response('Forbidden', { status: 403 });
  const { path = [] } = await params;
  const upstream = `${RUNTIME}/tenants/${session.tenantId}/webhook-endpoints/${path.map(encodeURIComponent).join('/')}`;
  const res = await fetch(upstream, {
    method: req.method,
    headers: { 'X-TenancyEngine-Api-Key': process.env.TE_API_KEY!, 'Content-Type': 'application/json' },
    body: ['GET', 'HEAD'].includes(req.method) ? undefined : await req.text(),
  });
  return new Response(res.body, { status: res.status, headers: { 'Content-Type': 'application/json' } });
}
export { proxy as GET, proxy as POST, proxy as PATCH, proxy as DELETE };

Only allow the people in your product who should manage integrations (canManageIntegrations above is your own rule). Then render <WebhookEndpointsPortal client={createFetchWebhookPortalClient({ baseUrl: '/api/webhook-endpoints' })} />.

TenancyEngine platform documentation