Webhook Management
This section provides a guide to managing Webhook endpoints and handling Webhook attempts within your Blocklet applications, enabling you to automate workflows and react to events on Blocklet Server. For details on directly interacting with the Blocklet Server API via GraphQL, refer to the GraphQL Client section.
Webhook Endpoints#
Webhook endpoints are URLs where Blocklet Server sends event notifications. You can configure these endpoints to receive real-time updates about various activities happening on your Blocklet. Each endpoint can be configured with specific events it should listen for.
Here's a high-level overview of the webhook process:
Create a Webhook Endpoint#
Use the createWebhookEndpoint
method to register a new Webhook endpoint with Blocklet Server. This allows your application to receive automated notifications for specified events.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet managing the webhook. |
|
| An object containing the details for the new webhook endpoint. |
ABTNodeClient.WebhookEndpointStateInput
Fields
Name | Type | Description |
---|---|---|
|
| Optional. A unique identifier for the webhook endpoint. If not provided, one will be generated. |
|
| The API version to use for the webhook events (e.g., "1.0"). |
|
| The URL where webhook events will be sent. |
|
| Optional. An optional description for the webhook endpoint. |
|
| An array of event types and sources to enable for this endpoint. |
|
| Optional. Custom metadata associated with the endpoint. |
|
| Optional. The status of the endpoint (e.g., "enabled", "disabled"). |
|
| Optional. Timestamp of creation. |
|
| Optional. Timestamp of last update. |
ABTNodeClient.EnableEventInput
Fields
Name | Type | Description |
---|---|---|
|
| The type of event to enable (e.g., "user.created", "blocklet.started"). |
|
| The source of the event (e.g., a Blocklet DID, "system"). |
Returns
Name | Type | Description |
---|---|---|
|
| The newly created webhook endpoint object. |
Example
import ABTNodeClient from '@abtnode/client';
async function createWebhookEndpoint(teamDid, webhookUrl) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.createWebhookEndpoint({
teamDid,
input: {
apiVersion: '1.0',
url: webhookUrl,
description: 'Webhook for user creation and update events',
enabledEvents: [
{ type: 'user.created', source: teamDid },
{ type: 'user.updated', source: teamDid },
],
},
});
console.log('Webhook endpoint created successfully:', response.data.id);
return response.data;
} catch (error) {
console.error('Error creating webhook endpoint:', error);
throw error;
}
}
// Usage example (replace with actual team DID and your webhook URL)
// createWebhookEndpoint('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P', 'https://your-app.com/webhooks');
Example Response
{
"code": 0,
"data": {
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Webhook for user creation and update events",
"enabledEvents": [
{
"type": "user.created",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
},
{
"type": "user.updated",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
}
],
"metadata": {},
"status": "enabled",
"createdAt": 1678886400000,
"updatedAt": 1678886400000
}
}
This example demonstrates how to create a new webhook endpoint that listens for user.created
and user.updated
events originating from a specific team DID.
Update a Webhook Endpoint#
Use the updateWebhookEndpoint
method to modify the details of an existing webhook endpoint, such as its URL, description, or enabled events.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet managing the webhook. |
|
| The unique identifier of the webhook endpoint to update. |
|
| An object containing the fields to update for the webhook endpoint. |
Returns
Name | Type | Description |
---|---|---|
|
| The updated webhook endpoint object. |
Example
import ABTNodeClient from '@abtnode/client';
async function updateWebhookEndpoint(teamDid, endpointId, newDescription) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.updateWebhookEndpoint({
teamDid,
id: endpointId,
data: {
description: newDescription,
},
});
console.log('Webhook endpoint updated successfully:', response.data.id);
return response.data;
} catch (error) {
console.error('Error updating webhook endpoint:', error);
throw error;
}
}
// Usage example (replace with actual team DID, endpoint ID, and new description)
// updateWebhookEndpoint('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P', 'wh_someGeneratedId', 'Updated description for user events');
Example Response
{
"code": 0,
"data": {
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Updated description for user events",
"enabledEvents": [
{
"type": "user.created",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
},
{
"type": "user.updated",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
}
],
"metadata": {},
"status": "enabled",
"createdAt": 1678886400000,
"updatedAt": 1678886400000
}
}
This example updates the description of an existing webhook endpoint identified by its ID.
Delete a Webhook Endpoint#
Use the deleteWebhookEndpoint
method to remove a webhook endpoint from Blocklet Server. This will stop sending event notifications to the specified URL.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet managing the webhook. |
|
| The unique identifier of the webhook endpoint to delete. |
Returns
Name | Type | Description |
---|---|---|
|
| The deleted webhook endpoint object. |
Example
import ABTNodeClient from '@abtnode/client';
async function deleteWebhookEndpoint(teamDid, endpointId) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.deleteWebhookEndpoint({
teamDid,
id: endpointId,
});
console.log('Webhook endpoint deleted successfully:', response.data.id);
return response.data;
} catch (error) {
console.error('Error deleting webhook endpoint:', error);
throw error;
}
}
// Usage example (replace with actual team DID and endpoint ID)
// deleteWebhookEndpoint('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P', 'wh_someGeneratedId');
Example Response
{
"code": 0,
"data": {
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Webhook for user creation and update events",
"enabledEvents": [],
"metadata": {},
"status": "deleted",
"createdAt": 1678886400000,
"updatedAt": 1678886400000
}
}
This example deletes a specified webhook endpoint, halting all future notifications to its URL.
Get a Webhook Endpoint#
Use the getWebhookEndpoint
method to retrieve detailed information about a single webhook endpoint by its ID.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet that owns the webhook endpoint. |
|
| The unique identifier of the webhook endpoint to retrieve. |
Returns
Name | Type | Description |
---|---|---|
|
| The requested webhook endpoint object, including associated user information. |
Example
import ABTNodeClient from '@abtnode/client';
async function getSingleWebhookEndpoint(teamDid, endpointId) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.getWebhookEndpoint({
teamDid,
id: endpointId,
});
console.log(`Retrieved webhook endpoint ${response.data.id}:`, response.data.description);
return response.data;
} catch (error) {
console.error('Error retrieving webhook endpoint:', error);
throw error;
}
}
// Usage example (replace with actual team DID and endpoint ID)
// getSingleWebhookEndpoint('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P', 'wh_someGeneratedId');
Example Response
{
"data": {
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Webhook for user creation and update events",
"enabledEvents": [
{
"type": "user.created",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
},
{
"type": "user.updated",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
}
],
"metadata": {},
"status": "enabled",
"createdAt": 1678886400000,
"updatedAt": 1678886400000,
"createUser": {
"did": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P",
"pk": "0x...",
"role": "owner",
"avatar": "",
"fullName": "Admin User",
"email": "admin@example.com",
"approved": true,
"createdAt": 1678800000000,
"updatedAt": 1678800000000,
"locale": "en"
},
"updateUser": {
"did": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P",
"pk": "0x...",
"role": "owner",
"avatar": "",
"fullName": "Admin User",
"email": "admin@example.com",
"approved": true,
"createdAt": 1678800000000,
"updatedAt": 1678800000000,
"locale": "en"
}
}
}
This example retrieves the full details, including user information, for a specific webhook endpoint.
Get Webhook Endpoints#
Use the getWebhookEndpoints
method to retrieve a paginated list of all webhook endpoints configured for a given team DID.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet whose webhook endpoints are to be retrieved. |
|
| Optional. Pagination parameters. |
ABTNodeClient.PagingInput
Fields
Name | Type | Description |
---|---|---|
|
| The total number of items available across all pages. |
|
| The maximum number of items to return per page. |
|
| The total number of pages available. |
|
| The current page number to retrieve (1-indexed). |
Returns
Name | Type | Description |
---|---|---|
|
| An array of webhook endpoint objects, including associated user information. |
|
| Pagination metadata. |
Example
import ABTNodeClient from '@abtnode/client';
async function getWebhookEndpoints(teamDid) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.getWebhookEndpoints({
teamDid,
paging: { page: 1, pageSize: 10 },
});
console.log(`Found ${response.list.length} webhook endpoints:`,
response.list.map(endpoint => endpoint.id));
return response.list;
} catch (error) {
console.error('Error getting webhook endpoints:', error);
throw error;
}
}
// Usage example (replace with actual team DID)
// getWebhookEndpoints('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P');
Example Response
{
"list": [
{
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Webhook for user creation and update events",
"enabledEvents": [
{
"type": "user.created",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
},
{
"type": "user.updated",
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
}
],
"metadata": {},
"status": "enabled",
"createdAt": 1678886400000,
"updatedAt": 1678886400000,
"createUser": {
"did": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P",
"fullName": "Admin User"
}
}
],
"paging": {
"total": 1,
"pageSize": 10,
"pageCount": 1,
"page": 1
}
}
This example retrieves a list of the first 10 webhook endpoints for a specified team, showing their IDs.
Webhook Attempts#
Webhook attempts represent individual delivery attempts of an event notification to a configured webhook endpoint. You can inspect these attempts to troubleshoot delivery failures or monitor webhook activity.
Get Webhook Attempts#
Use the getWebhookAttempts
method to retrieve a paginated list of webhook delivery attempts. You can filter attempts by eventId
or webhookId
.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet managing the webhooks. |
|
| An object specifying the |
|
| Optional. Pagination parameters. |
ABTNodeClient.RequestAttemptIdInput
Fields
Name | Type | Description |
---|---|---|
|
| Optional. The ID of the event for which to retrieve attempts. |
|
| Optional. The ID of the webhook endpoint for which to retrieve attempts. |
Returns
Name | Type | Description |
---|---|---|
|
| An array of webhook attempt objects, including associated endpoint and event information. |
|
| Pagination metadata. |
ABTNodeClient.WebhookAttemptWithEndpointEventState
Fields
Name | Type | Description |
---|---|---|
|
| The unique identifier for this webhook attempt. |
|
| The ID of the event that triggered this attempt. |
|
| The ID of the webhook endpoint this attempt was sent to. |
|
| The status of the attempt (e.g., "succeeded", "failed", "pending"). |
|
| The HTTP status code returned by the endpoint (if any). |
|
| The response body from the endpoint (if any). |
|
| The number of retries for this attempt. |
|
| Timestamp when the attempt was created. |
|
| Timestamp when the attempt was last updated. |
|
| Details of the webhook endpoint. |
|
| Details of the event that triggered the webhook. |
|
| The entity that triggered the webhook (e.g., "system", "user"). |
|
| The source of the trigger (e.g., "automation", "manual"). |
Example
import ABTNodeClient from '@abtnode/client';
async function getWebhookAttempts(teamDid, webhookId) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.getWebhookAttempts({
teamDid,
input: { webhookId },
paging: { page: 1, pageSize: 10 },
});
console.log(`Found ${response.list.length} webhook attempts for webhook ${webhookId}:`);
response.list.forEach(attempt => {
console.log(`- Attempt ID: ${attempt.id}, Status: ${attempt.status}, Response Status: ${attempt.responseStatus}`);
});
return response.list;
} catch (error) {
console.error('Error getting webhook attempts:', error);
throw error;
}
}
// Usage example (replace with actual team DID and webhook ID)
// getWebhookAttempts('did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P', 'wh_someGeneratedId');
Example Response
{
"list": [
{
"id": "att_someAttemptId",
"eventId": "evt_someEventId",
"webhookId": "wh_someGeneratedId",
"status": "succeeded",
"responseStatus": 200,
"responseBody": {},
"retryCount": 0,
"createdAt": 1678886400000,
"updatedAt": 1678886400000,
"endpoint": {
"id": "wh_someGeneratedId",
"apiVersion": "1.0",
"url": "https://your-app.com/webhooks",
"description": "Webhook for user creation and update events",
"enabledEvents": [],
"metadata": {},
"status": "enabled",
"createdAt": 1678886400000,
"updatedAt": 1678886400000
},
"event": {
"id": "evt_someEventId",
"type": "user.created",
"apiVersion": "1.0",
"data": {},
"objectType": "User",
"objectId": "user_someUserId",
"request": {},
"pendingWebhooks": 0,
"metadata": {},
"createdAt": 1678886300000,
"updatedAt": 1678886300000,
"source": "did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P"
},
"triggeredBy": "system",
"triggeredFrom": "automation"
}
],
"paging": {
"total": 1,
"pageSize": 10,
"pageCount": 1,
"page": 1
}
}
This example retrieves the first 10 webhook attempts for a specific webhook endpoint, displaying their status and response codes.
Retry a Webhook Attempt#
Use the retryWebhookAttempt
method to re-attempt the delivery of a failed webhook event. This can be useful for re-processing events after an issue with your endpoint has been resolved.
Parameters
Name | Type | Description |
---|---|---|
|
| The DID of the team or Blocklet managing the webhook. |
|
| An object containing the |
ABTNodeClient.RequestAttemptInput
Fields
Name | Type | Description |
---|---|---|
|
| The ID of the event associated with the attempt. |
|
| The ID of the webhook endpoint associated with the attempt. |
|
| The ID of the specific attempt to retry. |
|
| The DID of the team or Blocklet managing the webhook. (Note: This is duplicated in the top-level |
Returns
Name | Type | Description |
---|---|---|
|
| The retried webhook attempt object. |
Example
import ABTNodeClient from '@abtnode/client';
async function retryWebhookAttempt(teamDid, eventId, webhookId, attemptId) {
const client = new ABTNodeClient('http://localhost:8080'); // Replace with your Blocklet Server endpoint
try {
const response = await client.retryWebhookAttempt({
teamDid,
input: {
eventId,
webhookId,
attemptId,
teamDid, // teamDid is part of input as well
},
});
console.log('Webhook attempt retried successfully:', response.data.id, 'New Status:', response.data.status);
return response.data;
} catch (error) {
console.error('Error retrying webhook attempt:', error);
throw error;
}
}
// Usage example (replace with actual DIDs and IDs)
// retryWebhookAttempt(
// 'did:abt:zNKxVGF19f56e9qB4L9zF8Wz3t3V7t7P',
// 'evt_someEventId',
// 'wh_someGeneratedId',
// 'att_someFailedAttemptId'
// );
Example Response
{
"code": 0,
"data": {
"id": "att_someFailedAttemptId",
"eventId": "evt_someEventId",
"webhookId": "wh_someGeneratedId",
"status": "pending",
"responseStatus": 0,
"responseBody": {},
"retryCount": 1,
"createdAt": 1678886400000,
"updatedAt": 1678886500000,
"triggeredBy": "user",
"triggeredFrom": "manual"
}
}
This example demonstrates how to retry a specific webhook delivery attempt, which will trigger a new attempt to send the event.
This section provided a comprehensive overview of managing webhook endpoints and their delivery attempts using the Blocklet SDK. You are now equipped to configure event notifications and monitor their delivery within your Blocklet applications. Proceed to the API Reference for a full, automatically generated list of all available methods and types.