* Simplified generics and imports for items page snippets * Simplified generics and imports for files page snippets * Fixing simplified generic snippets in items page * Simplified generics and imports for activity page snippets * Simplified generics and imports for collections page snippets * Simplified generics and imports for dashboards page snippets * Simplified generics and imports for extensions page snippets * Simplified generics and imports for fields page snippets * Simplified generics and imports for flows page snippets * Simplified generics and imports for folders page snippets * Simplified generics and imports for notifications page snippets * Simplified generics and imports for operations page snippets * Simplified generics and imports for panels page snippets * Simplified generics and imports for permissions page snippets * Simplified generics and imports for presets page snippets * Simplified generics and imports for relations page snippets * Simplified generics and imports for relations page snippets * Simplified generics and imports for revisions page snippets * Simplified generics and imports for roles page snippets * Consolidated imports for schema page snippets * Simplified generics and imports for server page snippets * Simplified generics and imports for settings page snippets * Fixed mixed up snippets and simplified generics and imports for shares page snippets * Simplified generics and imports for translation page snippets * Fixed mixed up snippets and simplified generics and imports for user page snippets * Simplified generics and imports fo uutilitie pages snippets * Simplified generics and imports for webhook pages snippets * Simplified generics and imports for authentication pages snippets * Consolidated imports for query pages sdk snippets * Format files * Update lockfile * Fix spelling * Format snippets * Aling `result` const * Small clean-ups - Align `SEARCH` snippets, move "Learn more..." next to other hint - ids -> IDs - Other alignments --------- Co-authored-by: Bevis Halsey-Perry <hi@be7.is> Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
14 KiB
description, readTime, pageClass
| description | readTime | pageClass |
|---|---|---|
| REST and GraphQL API documentation on the Webhooks collection in Directus. | 5 min read | page-reference |
Webhooks
Webhooks are configured within the App (no code required) and send HTTP requests to an external service when a specific event is triggered.
The Webhook Object
id integer
Primary key of the webhook.
name string
Name for the webhook. Shown in the Admin App.
method string
HTTP method to use. One of GET, POST.
url string
Where to send the request too.
status string
Status of the webhook. One of active, inactive.
data boolean
Whether or not to send the event data to the external endpoint.
actions csv
When to fire the webhook. Can contain create, update, delete.
collections csv
What collections to fire this webhook on.
{
"data": {
"id": 1,
"name": "Build Website",
"method": "POST",
"url": "https://example.com/",
"status": "active",
"data": true,
"actions": ["create", "update"],
"collections": ["articles"]
}
}
List Webhooks
List all webhooks that exist in Directus.
Request
GET /webhooks
SEARCH /webhooks
If using SEARCH you can provide a query object as the body of your request.
POST /graphql/system
type Query {
webhooks: [directus_webhooks]
}
import { createDirectus, rest, readWebhooks } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readWebhooks(query_object));
Query Parameters
Supports all global query parameters.
Response
An array of up to limit webhook objects. If no items are available, data will be an empty array.
Example
GET /webhooks
SEARCH /webhooks
POST /graphql/system
query {
webhooks {
url
method
}
}
import { createDirectus, rest, readWebhooks } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
readWebhooks({
fields: ['*'],
})
);
Retrieve a Webhook
List an existing webhook by primary key.
Request
GET /webhooks/:id
POST /graphql/system
type Query {
webhooks_by_id(id: ID!): directus_webhooks
}
import { createDirectus, rest, readWebhook } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(readWebhook(webhook_id, query_object));
Query Parameters
Supports all global query parameters.
Returns
Returns the requested webhook object.
Examples
GET /webhooks/15
POST /graphql/system
query {
webhooks_by_id(id: 15) {
url
actions
method
}
}
import { createDirectus, rest, readWebhook } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
readWebhook('2', {
fields: ['*'],
})
);
Create a Webhook
Create a new webhook.
Request
POST /webhooks
Provide a webhook object as the body of your request.
POST /graphql/system
type Mutation {
create_webhooks_item(data: create_directus_webhooks_input!): directus_webhooks
}
import { createDirectus, rest, createWebhook } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(createWebhook(webhook_object));
Query Parameters
Supports all global query parameters.
Request Body
A partial webhook object.
name, actions, collections, and url are required.
Response
Returns the webhook object for the created webhook.
Example
POST /webhooks
{
"name": "Example",
"actions": ["create", "update"],
"collections": ["articles"],
"url": "https://example.com"
}
POST /graphql/system
mutation {
create_webhooks_item(
data: { name: "Example", actions: ["create", "update"], collections: ["articles"], url: "https://example.com" }
) {
id
name
}
}
import { createDirectus, rest, createWebhook } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
createWebhook({
name: 'Articles Activity',
method: 'POST',
collections: 'articles',
actions: ['create', 'update', 'delete'],
url: 'https://directus.example.com/articles_activity',
})
);
Create Multiple Webhook
Create multiple new webhooks.
Request
POST /webhooks
Provide an array of webhook objects as the body of your request.
POST /graphql/system
type Mutation {
create_webhooks_items(data: [create_directus_webhooks_input!]!): [directus_webhooks]
}
import { createDirectus, rest, createWebhooks } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(createWebhooks(webhook_object_array));
Query Parameters
Supports all global query parameters.
Request Body
An array of partial webhook object.
name, actions, collections, and url are required.
Response
Returns the webhook objects for the created webhooks.
Example
POST /webhooks
[
{
"name": "Example",
"actions": ["create", "update"],
"collections": ["articles"],
"url": "https://example.com"
},
{
"name": "Second Example",
"actions": ["delete"],
"collections": ["articles"],
"url": "https://example.com/on-delete"
}
]
POST /graphql/system
mutation {
create_webhooks_items(
data: [
{ name: "Example", actions: ["create", "update"], collections: ["articles"], url: "https://example.com" }
{ name: "Second Example", actions: ["delete"], collections: ["articles"], url: "https://example.com/on-delete" }
]
) {
id
name
}
}
import { createDirectus, rest, createWebhooks } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
createWebhooks([
{
name: 'Articles Activity',
method: 'POST',
collections: 'articles',
actions: ['create', 'update', 'delete'],
url: 'https://directus.example.com/articles_activity',
},
{
name: 'Author Changes',
method: 'POST',
collections: 'authors',
actions: ['update'],
url: 'https://directus.example.com/authors_changes',
},
])
);
Update a Webhook
Update an existing webhook.
Request
PATCH /webhooks/:id
Provide a partial webhook object as the body of your request.
POST /graphql/system
type Mutation {
update_webhooks_item(id: ID!, data: update_directus_webhooks_input!): directus_webhooks
}
import { createDirectus, rest, updateWebhook } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(updateWebhook(webhook_id, partal_webhook_object));
Query Parameters
Supports all global query parameters.
Request Body
A partial webhook object.
Response
Returns the webhook object for the updated webhook.
Example
PATCH /webhooks/15
{
"name": "Build Website"
}
POST /graphql/system
mutation {
update_webhooks_item(id: 15, data: { name: "Build Website" }) {
name
}
}
import { createDirectus, rest, updateWebhook } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
updateWebhook('6', {
actions: ['update', 'delete'],
})
);
Update Multiple Webhooks
Update multiple existing webhooks.
Request
PATCH /webhooks
{
"keys": webhook_id_array,
"data": partial_webhook_object
}
POST /graphql/system
type Mutation {
update_webhooks_items(ids: [ID!]!, data: update_directus_webhooks_input!): [directus_webhooks]
}
import { createDirectus, rest, updateWebhooks } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(updateWebhooks(webhook_id_array, partial_webhook_object));
Query Parameters
Supports all global query parameters.
Request Body
keys Required
Array of primary keys of the webhooks you'd like to update.
data Required
Any of the webhook object's properties.
Response
Returns the webhook objects for the updated webhooks.
REST API
Example
PATCH /webhooks
{
"keys": [15, 41],
"data": {
"name": "Build Website"
}
}
POST /graphql/system
mutation {
update_webhooks_items(ids: [15, 41], data: { name: "Build Website" }) {
name
}
}
import { createDirectus, rest, updateWebhooks } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(
updateWebhooks(['5', '6'], {
status: 'inactive',
})
);
Delete a Webhook
Delete an existing webhook.
Request
DELETE /webhooks/:id
POST /graphql/system
type Mutation {
delete_webhooks_item(id: ID!): delete_one
}
import { createDirectus, rest, deleteWebhook } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(deleteWebhook(webhook_id));
Response
Empty body.
Example
DELETE /webhooks/15
POST /graphql/system
mutation {
delete_webhooks_item(id: 15) {
id
}
}
import { createDirectus, rest, deleteWebhook } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(deleteWebhook('1'));
Delete Multiple Webhooks
Delete multiple existing webhooks.
Request
DELETE /webhooks
Provide an array of webhook IDs as the body of your request.
POST /graphql/system
type Mutation {
delete_webhooks_items(ids: [ID!]!): delete_many
}
import { createDirectus, rest, deleteWebhooks } from '@directus/sdk';
const client = createDirectus('directus_project_url').with(rest());
const result = await client.request(deleteWebhooks(webhook_id_array));
Request Body
An array of webhook primary keys
Response
Empty body.
Example
DELETE /webhooks
[2, 15, 41]
POST /graphql/system
mutation {
delete_webhooks_items(ids: [2, 15, 41]) {
ids
}
}
import { createDirectus, rest, deleteWebhooks } from '@directus/sdk';
const client = createDirectus('https://directus.example.com').with(rest());
const result = await client.request(deleteWebhooks(['2', '3']));