Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API to manage permissions in bulk. Specifically, the "Permissions" resource with the "Create Multiple" operation allows users to create multiple permission entries at once by sending an array of partial permission objects.

This is useful in scenarios where you need to set up or update access controls for various roles and collections programmatically, such as initializing a new project with predefined permissions or synchronizing permissions across environments.

Example use case:
You want to assign read and create permissions on the "pages" collection to a specific role, specifying which fields are accessible. Instead of creating each permission individually, you provide an array of permission objects, and the node creates them all in one request.

Properties

Name Meaning
Data (JSON) An array of partial permission objects to create. Each object must include at least the collection (the target collection name) and action (the permission action like "read", "create", etc.). Optionally, specify role and fields. Example:
json<br>[<br> {<br> "collection": "pages",<br> "action": "read",<br> "role": "role-id",<br> "fields": ["id", "title"]<br> },<br> {<br> "collection": "pages",<br> "action": "create",<br> "role": "role-id",<br> "fields": ["id", "title"]<br> }<br>]<br>

Output

The node outputs the response from the Directus API after creating the permissions. The output JSON contains the created permission objects with their full details as returned by the API.

  • The output is an array of JSON objects, each representing a created permission.
  • No binary data is produced by this operation.

Dependencies

  • Requires a valid connection to a Directus instance via an API key credential configured in n8n.
  • The node uses the Directus REST API endpoint permissions with HTTP POST method.
  • Proper permissions on the Directus API side are required to create permissions.

Troubleshooting

  • Invalid JSON in Data property: If the JSON array provided in the "Data (JSON)" property is malformed, the node will throw a parsing error. Ensure the JSON syntax is correct.
  • Missing required fields: Each permission object must have at least collection and action. Omitting these will cause API errors.
  • API authentication errors: If the API key or credentials are invalid or lack permission to create permissions, the node will return an authorization error.
  • Permission conflicts: Attempting to create duplicate or conflicting permissions may result in API errors.
  • To resolve errors, verify the input JSON, check API credentials, and ensure the user has rights to modify permissions.

Links and References

Discussion