Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API to manage various resources, including Roles. Specifically, for the Roles resource and the Create Multiple operation, it allows users to create multiple role entries in a single API call by sending an array of role objects.

This is beneficial when you need to batch-create several roles at once, such as setting up user permissions or access levels in bulk during initial project setup or migration. For example, you might create roles like "Interns", "Customers", and "Admins" simultaneously, each with different access rights and metadata.

Properties

Name Meaning
Data (JSON) An array of partial role objects to create. Each object can include properties like name, icon, description, admin_access, and app_access. The input should be a JSON array representing multiple roles.

Example value for Data (JSON):

[
  {
    "name": "Interns",
    "icon": "verified_user",
    "description": null,
    "admin_access": false,
    "app_access": true
  },
  {
    "name": "Customers",
    "icon": "person",
    "description": null,
    "admin_access": false,
    "app_access": false
  }
]

Output

The output is an array of JSON objects, each representing the created role(s) returned from the Directus API. The structure corresponds to the Directus role object schema, typically including fields such as:

  • id: Unique identifier of the role.
  • name: Name of the role.
  • icon: Icon associated with the role.
  • description: Description text.
  • admin_access: Boolean indicating if the role has admin privileges.
  • app_access: Boolean indicating if the role has app access.
  • Other metadata fields as defined by Directus.

No binary data output is involved in 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 endpoints, specifically the POST request to /roles for creating multiple roles.
  • Proper permissions on the Directus API are necessary to create roles.

Troubleshooting

  • Invalid JSON Input: 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.
  • API Authentication Errors: If the API key or credentials are invalid or missing, the node will fail with authentication errors. Verify that the Directus API credentials are correctly set up in n8n.
  • Permission Denied: If the authenticated user does not have permission to create roles, the API will return an authorization error.
  • Empty or Missing Data: Providing an empty array or no data will result in no roles being created; ensure the input contains valid role objects.
  • API Rate Limits or Server Errors: Network issues or server-side problems may cause failures; check the Directus server status and retry as needed.

Links and References

Discussion