Directus icon

Directus

Consume Directus API

Overview

The Directus - Permission: Create operation in this n8n node allows you to create a new permission rule for a specific collection in your Directus instance. This is useful for programmatically managing access control, such as defining which roles can perform certain CRUD (Create, Read, Update, Delete) operations on collections.

Common scenarios:

  • Automating the setup of permissions when deploying new collections.
  • Integrating permission management into CI/CD pipelines.
  • Dynamically adjusting access rules based on business logic or external triggers.

Practical example:
You could use this node to automatically grant "read" access to a "customers" collection for a specific role whenever a new user is onboarded.


Properties

Name Type Meaning
Collection options The collection to which this permission applies.
Action options The CRUD operation this permission rule applies to (create, read, update, delete).
JSON/RAW Parameters boolean If enabled, allows setting body parameters via raw JSON instead of the UI fields.
Body Parameters json (Shown if JSON/RAW Parameters is true) Raw JSON object specifying the permission details.

Output

  • The output will be a single object in the json field containing the created permission rule as returned by the Directus API.
  • The structure typically includes fields like id, collection, action, and other permission attributes defined in the request or set by Directus.

Example output:

{
  "id": 1,
  "collection": "customers",
  "action": "create",
  "role": "12345678-abcd-efgh-ijkl-1234567890ab",
  "permissions": { /* ... */ },
  "fields": "*",
  "validation": null,
  "presets": {},
  "limit": null,
  "status": "active"
}

Dependencies

  • External Service: Requires access to a Directus instance with API credentials.
  • n8n Credentials: You must configure Directus API credentials (directusApi) in n8n.

Troubleshooting

Common issues:

  • Missing or invalid credentials: Ensure that the Directus API credentials are correctly configured in n8n.
  • Invalid collection or action: Double-check that the specified collection exists and the action is one of the allowed values.
  • Malformed JSON: If using JSON/RAW Parameters, ensure the JSON is valid; otherwise, the node may throw a parsing error.
  • Insufficient permissions: The API user must have rights to create permissions in Directus.

Error messages:

  • "Cannot read property 'data' of undefined": Likely due to an unexpected response from the API—check your input and Directus server status.
  • "Request failed with status code 401": Authentication issue—verify your credentials.
  • "400 Bad Request": Usually indicates malformed input or missing required fields.

Links and References

Discussion