Skip to content

Webhooks overview

Understand how Scalekit webhooks deliver real-time notifications about authentication and user management events in your application

Scalekit sends webhooks to deliver real-time notifications about authentication and user management events. Webhooks provide instant updates when users sign up, log in, or when directory changes occur, eliminating the need to poll for changes.

Webhook delivery flow UserScalekitYour AppScalekit SDK Trigger event (login, signup, directory sync) Queue webhook event POST webhook payload Verify webhook signature Process event data Return success response (200/201)

Webhooks enable responsive integrations that react immediately to changes in Scalekit. Instead of polling APIs to check for updates, your application receives instant notifications about important events.

Key benefits include:

  • Real-time updates: Get notified immediately when events occur
  • Reduced API calls: No need to poll for changes
  • Event-driven architecture: Build responsive workflows that react to user actions
  • Reliable delivery: Scalekit ensures webhook delivery with automatic retries

All webhook payloads follow a standardized structure with metadata and event-specific data in the data field.

User created event payload
{
"spec_version": "1",
"id": "evt_123456789",
"object": "DirectoryUser",
"environment_id": "env_123456789",
"occurred_at": "2024-08-21T10:20:17.072Z",
"organization_id": "org_123456789",
"type": "organization.directory.user_created",
"data": {
"user_id": "usr_123456789",
"email": "user@example.com",
"name": "John Doe"
}
}
PropertyDescription
spec_versionThe version of the event specification format. Currently “1”.
idA unique identifier for the event (e.g., evt_123456789).
objectThe type of object that triggered the event (e.g., “DirectoryUser”, “Directory”, “Connection”).
environment_idThe ID of the environment where the event occurred.
occurred_atISO 8601 timestamp indicating when the event occurred.
organization_idThe ID of the organization associated with the event.
typeThe specific event type (e.g., “organization.directory.user_created”).
dataEvent-specific payload containing details relevant to the event type.

Register webhook endpoints in the Scalekit dashboard to receive event notifications. Each endpoint can subscribe to specific event types and receive payloads when those events occur.

  1. Access webhook settings

    Navigate to Dashboard > Webhooks in your Scalekit environment.

  2. Create new endpoint

    Click “Create Endpoint” and provide:

    • Endpoint URL: Your application’s webhook handler URL
    • Event types: Select which events to receive
    • Description: Optional description for your reference
  3. Copy webhook secret

    After creating the endpoint, copy the webhook secret for signature verification.

  4. Test the endpoint

    Use the test functionality in the dashboard to send sample events to your endpoint.

Create HTTP endpoints in your application to receive webhook payloads from Scalekit.

Express webhook handler
const express = require('express');
const app = express();
// Parse JSON payloads
app.use(express.json());
app.post('/webhook', async (req, res) => {
try {
// Extract webhook data
const event = req.body;
const headers = req.headers;
// Verify webhook signature (recommended)
const isValid = await scalekit.verifyWebhookPayload(
process.env.SCALEKIT_WEBHOOK_SECRET,
headers,
event
);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Process the event
await processWebhookEvent(event);
// Return success response
res.status(200).json({ received: true });
} catch (error) {
console.error('Webhook processing error:', error);
res.status(500).json({ error: 'Internal server error' });
}
});

Scalekit expects specific HTTP status codes in response to webhook deliveries.

Status CodeDescription
200 OKWebhook processed successfully
201 Created RecommendedWebhook processed and resource created
202 AcceptedWebhook accepted for asynchronous processing
Status CodeDescription
400 Bad RequestInvalid payload or malformed request
401 UnauthorizedInvalid webhook signature
403 ForbiddenWebhook not authorized
422 Unprocessable EntityValid request but cannot process
500 Internal Server ErrorServer error during processing