Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API, allowing users to perform various operations on Directus resources. Specifically, for the Roles resource with the Create operation, it enables creating new roles within a Directus project by sending role data to the API.

This is useful in scenarios where you want to automate user role management in Directus, such as programmatically adding new roles during onboarding processes or syncing roles from another system.

Example use cases:

  • Automatically create a "Marketing" role with specific permissions when setting up a new project.
  • Add temporary roles for contractors or interns via workflow automation.
  • Manage roles dynamically based on external triggers or data sources.

Properties

Name Meaning
Data (JSON) A JSON object representing a partial role object to create. This includes fields like name, icon, description, admin_access, and app_access. The JSON should conform to the Directus role object structure.

Example of the expected JSON input:

{
  "name": "Interns",
  "icon": "verified_user",
  "description": null,
  "admin_access": false,
  "app_access": true
}

Output

The node outputs the response from the Directus API after creating the role. The output is a JSON object containing the created role's details as returned by the API. This typically includes the role's unique ID and all properties that were set or defaulted by Directus.

The output JSON structure corresponds to the Directus role object schema, which may include 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 access to the app.

No binary data output is involved in this operation.

Dependencies

  • Requires an active connection to a Directus instance via an API key credential configured in n8n.
  • The node uses the Directus REST API endpoint for roles (POST /roles).
  • Proper permissions are required on the API key to create roles in the Directus project.

Troubleshooting

  • Invalid JSON Input: If the JSON provided in the "Data (JSON)" property is malformed or missing required fields, the API will return an error. Ensure the JSON is valid and matches the expected role object format.
  • Authentication Errors: If the API key credential is invalid or lacks permission to create roles, the node will fail with an authentication or authorization error. Verify the API key and its permissions.
  • API Endpoint Errors: Network issues or incorrect Directus instance URLs can cause request failures. Confirm connectivity and correct configuration.
  • Continue On Fail: If enabled, the node will continue processing other items even if one fails, returning error messages in the output JSON.

Links and References


This summary focuses on the "Roles" resource with the "Create" operation as requested, describing how to provide input, what output to expect, and common considerations when using this node functionality.

Discussion