Directus icon

Directus

Consume Directus API

Overview

The Webhooks → Create Multiple operation in this n8n node allows you to create multiple webhooks at once in a Directus instance. This is particularly useful for automating the setup of several webhook endpoints that listen to various actions or collections within your Directus project. For example, you might want to set up webhooks to notify external services when articles are created, updated, or deleted.

Practical scenarios:

  • Bulk onboarding of webhook integrations for new projects.
  • Automated deployment scripts that need to register many webhooks at once.
  • Synchronizing Directus events with other systems (e.g., Slack, Zapier, custom APIs).

Properties

Name Type Meaning
Data (JSON) json An array of partial webhook objects. Each object must include name, actions, collections, and url. Used to define webhooks to create.

Output

  • The output will be an array of JSON objects, each representing a created webhook as returned by the Directus API.
  • The structure of each object matches the Directus Webhook Object, typically including fields such as:
    • id
    • name
    • status
    • actions
    • collections
    • url
    • headers
    • data
    • secret
    • created_at
    • updated_at
    • ...and other standard Directus webhook properties.

Example output:

[
  {
    "id": 1,
    "name": "Example",
    "status": "active",
    "actions": ["create", "update"],
    "collections": ["articles"],
    "url": "https://example.com",
    "headers": {},
    "data": {},
    "secret": null,
    "created_at": "2024-06-01T12:00:00Z",
    "updated_at": "2024-06-01T12:00:00Z"
  },
  ...
]

Dependencies

  • External Service: Requires access to a Directus instance with API credentials.
  • n8n Credentials: You must configure the directusApi credential in n8n, which should have permission to create webhooks.
  • Environment: No special environment variables are required beyond those needed for Directus connectivity.

Troubleshooting

Common issues:

  • Invalid Data Format: If the Data (JSON) property is not a valid JSON array or is missing required fields (name, actions, collections, url), the node will throw an error.
  • Permission Denied: If the provided Directus API credentials lack permission to create webhooks, the request will fail.
  • API Errors: Any errors from the Directus API (such as duplicate names, invalid URLs, or unsupported actions/collections) will be passed through as error messages in the output.

Error handling:

  • If "Continue On Fail" is enabled, failed items will return an object like { "error": "Error message here" } in the output array.

Links and References

Discussion