Directus icon

Directus

Consume Directus API

Overview

The Directus Webhooks (Create) operation node allows you to programmatically create new webhook definitions in a Directus instance. This is useful for automating the process of registering webhooks that notify external services when certain actions (like create, update, or delete) occur on specified collections within Directus.

Common scenarios:

  • Automatically registering webhooks during project setup or deployment.
  • Integrating Directus with other systems (e.g., triggering CI/CD pipelines, sending notifications, syncing data).
  • Managing webhook configurations as part of infrastructure-as-code workflows.

Practical example:
You want to notify an external service every time a new article is created or updated in your "articles" collection. You can use this node to register a webhook that POSTs to your service's endpoint whenever those events happen.


Properties

Name Type Meaning
Name String Name for the webhook. Shown in the Admin App.
Actions Multi-Options When to fire the webhook. Can include "create", "update", and/or "delete".
Collections Multi-Options The collections in Directus to monitor for the specified actions.
URL String The destination URL where the webhook payload will be sent.
JSON/RAW Parameters Boolean If enabled, allows setting parameters via a raw JSON input instead of individual fields.
Body Parameters JSON (Shown only if JSON/RAW Parameters is true) The full webhook definition as JSON or RAW.

Output

  • The output is a single object under the json field containing the response from the Directus API after creating the webhook.
  • The structure typically includes details about the newly created webhook, such as its ID, name, actions, collections, URL, and other metadata as returned by Directus.

Example output:

{
  "id": "123",
  "name": "Build Website",
  "actions": ["create", "update"],
  "collections": ["articles"],
  "url": "https://example.com/",
  // ...other Directus webhook properties
}

If the API returns a primitive value (string, number, boolean), it will be wrapped as { "result": <value> }.


Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: The node requires valid Directus API credentials (directusApi) configured in n8n.

Troubleshooting

Common issues:

  • Invalid URL: If the provided URL is not reachable or malformed, Directus may reject the webhook creation.
  • Missing required fields: All required properties (Name, Actions, Collections, URL) must be provided unless using raw JSON mode.
  • Incorrect JSON format: If using "JSON/RAW Parameters", ensure the JSON is valid; otherwise, parsing errors will occur.
  • Insufficient permissions: The API user must have permission to create webhooks in Directus.

Error messages:

  • "error": "Unexpected token ...": Indicates invalid JSON in the "Body Parameters" field.
  • "error": "Request failed with status code 401": Authentication issue—check your API credentials.
  • "error": "Field '...' is required": A required property was omitted.

Links and References

Discussion