Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Directus (DrWade) n8n node with Resource Permissions and Operation Create Multiple allows you to create multiple permission objects in a single API call within a Directus instance. This is particularly useful for bulk-assigning permissions to roles across collections, streamlining the process of setting up or updating access control policies.

Common scenarios:

  • Initial setup of a new Directus project where many permissions need to be defined at once.
  • Migrating or synchronizing permissions between environments.
  • Automating role-based access control updates as part of a CI/CD pipeline.

Practical example:
You have a new "Editor" role and want to grant it read and create access to the "pages" collection for specific fields. You can define both permissions in an array and create them in one workflow step.

Properties

Name Type Meaning
Data (JSON) json An array of partial permissions objects. Each object should specify at least action and collection. Used to define permissions.

Example value:

[
  {
    "collection": "pages",
    "action": "read",
    "role": "c86c2761-65d3-43c3-897f-6f74ad6a5bd7",
    "fields": ["id", "title"]
  },
  {
    "collection": "pages",
    "action": "create",
    "role": "c86c2761-65d3-43c3-897f-6f74ad6a5bd7",
    "fields": ["id", "title"]
  }
]

Output

  • The output will be a JSON object containing the result of the bulk creation operation.
  • The structure typically matches the response from the Directus API for creating permissions, which is usually an array of the created permission objects, each reflecting the properties sent plus any additional metadata assigned by Directus (such as IDs, timestamps, etc.).

Example output:

{
  "id": "generated-id",
  "collection": "pages",
  "action": "read",
  "role": "c86c2761-65d3-43c3-897f-6f74ad6a5bd7",
  "fields": ["id", "title"],
  ...
}

or, if multiple:

[
  { "id": "...", "collection": "...", ... },
  { "id": "...", "collection": "...", ... }
]
  • If an error occurs and "Continue On Fail" is enabled, the output will contain an error field with the error message.

Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.

Troubleshooting

Common issues:

  • Invalid JSON in Data (JSON): If the input is not valid JSON, the node will throw a parsing error. Ensure your input is a properly formatted JSON array.
  • Missing required fields: Each permission object must include at least action and collection. Omitting these will result in an API error.
  • Role or Collection does not exist: If you reference a non-existent role or collection, Directus will return an error.
  • Insufficient permissions: The API user must have sufficient rights to create permissions; otherwise, you'll receive a permission denied error.

Error messages and resolutions:

  • "Unexpected token ...": Check your JSON syntax in the Data (JSON) property.
  • "Field 'action' is required": Make sure every object in your array includes the action property.
  • "Permission denied": Verify that your API credentials have admin or appropriate rights.

Links and References

Discussion