Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Webhooks → Create operation in this custom n8n node allows you to programmatically create new webhooks in a Directus instance. This is useful for automating the process of registering webhook endpoints that will be triggered by specific actions (such as create, update, or delete) on selected collections within Directus.

Common scenarios:

  • Automatically setting up integrations with external services when certain data changes occur in Directus.
  • Dynamically managing webhook registrations as part of deployment or configuration workflows.
  • Ensuring consistency and repeatability in environments where webhook setup needs to be automated.

Practical example:
You could use this node to register a webhook that notifies your CI/CD pipeline whenever an article is created or updated in your CMS, or to trigger a Slack notification when a user record is deleted.


Properties

Name Type Meaning
Name String The display name for the webhook. Shown in the Directus Admin App.
Actions Multi-Options Specifies which events should trigger the webhook. Options: create, update, delete.
Collections Multi-Options The collections in Directus to monitor for the specified actions.
URL String The endpoint URL where webhook requests will be sent.
JSON/RAW Parameters Boolean If enabled, allows specifying body parameters as raw JSON instead of using UI fields.
Body Parameters JSON (Shown only if JSON/RAW Parameters is true) Raw JSON object for additional webhook config.

Output

  • The output is a single json object representing the newly created webhook as returned by the Directus API.
  • The structure typically includes fields such as:
    • id: Unique identifier for the webhook.
    • name: The name given to the webhook.
    • url: The target URL.
    • actions: Array of actions that trigger the webhook.
    • collections: Array of collections the webhook is attached to.
    • Other metadata as provided by Directus.

Example output:

{
  "id": 1,
  "name": "Build Website",
  "url": "https://example.com/",
  "actions": ["create", "update"],
  "collections": ["articles"],
  "status": "active"
}

Note: The actual structure may include more fields depending on Directus version and configuration.


Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: The node requires valid Directus API credentials (directusApi) configured in n8n.
  • Network Access: The n8n instance must be able to reach both the Directus API and the webhook target URLs.

Troubleshooting

Common issues:

  • Invalid URL: If the URL is malformed or unreachable, Directus may reject the webhook or fail to deliver events.
  • Missing Required Fields: Omitting required properties (Name, Actions, Collections, URL) will result in errors.
  • Permission Denied: The API credentials used must have permission to manage webhooks in Directus.
  • JSON Parsing Errors: If "JSON/RAW Parameters" is enabled, ensure the JSON is well-formed; otherwise, parsing errors will occur.

Error messages:

  • "error": "Request failed with status code 401" – Check your API credentials.
  • "error": "Validation error: missing field X" – Ensure all required fields are filled.
  • "error": "Invalid JSON" – Double-check the syntax of any raw JSON input.

Links and References

Discussion