Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API to manage user data within a Directus instance. Specifically, the Users - List operation fetches a list of users from the Directus system. It supports flexible querying, filtering, sorting, and exporting of user data.

Common scenarios where this node is beneficial include:

  • Retrieving all or a subset of users for reporting or synchronization purposes.
  • Exporting user lists in various formats (JSON, CSV, XML) for external use.
  • Applying filters, search queries, and sorting to get targeted user subsets.
  • Using aggregation functions to compute statistics on user data fields.

Practical example:

  • An admin wants to export all registered users as a CSV file for offline analysis.
  • A workflow needs to fetch only the first 50 users who match certain criteria.
  • A report requires counting distinct user roles or calculating average login counts.

Properties

Name Meaning
Return All Boolean flag to return all matching users or limit the number of results.
Limit Number specifying the maximum number of users to return when "Return All" is false. Range: 1 to 100.
Split Into Items Boolean indicating whether to output each user as a separate item or as a single array.
JSON/RAW Parameters Boolean to choose between entering query/body parameters via UI fields or raw JSON input.
Body Parameters JSON input for body parameters when using JSON/RAW mode. Allows complex nested queries or filters.
Additional Fields Collection of optional parameters including:
- Aggregate: Aggregation functions like count, sum, average, min, max on specified fields.
- Binary Property for Export Data: Name of binary property to store exported file data.
- Deep (JSON): Nested relational dataset parameters.
- Export: Format to save API response as a file. Options: csv, json, xml.
- Fields: Comma-separated list of fields to return.
- File Name for Export Data: Filename without extension for exported data.
- Filter (JSON): Conditions to filter the user collection.
- Group By: Field(s) to group aggregation results by.
- Meta: Metadata to include in the response.
- Offset: Number of items to skip before fetching results.
- Search: Text query to filter users containing the string in any field.
- Sort: CSV of fields to sort by, prefix with "-" for descending, "?" for random order.

Output

The node outputs user data in the json field of each item. The structure corresponds to the user objects returned by the Directus API, which typically include user properties such as id, email, role, status, and metadata.

If the Export option is used, the node also outputs a binary property containing the exported file data in the selected format (CSV, JSON, or XML). The binary property name defaults to "data" but can be customized.

When Split Into Items is enabled, each user object is output as an individual item; otherwise, all users are output as a single array in one item.

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 for users.
  • No additional external dependencies beyond the Directus API and n8n environment.

Troubleshooting

  • Authentication errors: Ensure the API key credential is correctly set up and has permissions to access user data.
  • Invalid JSON input: When using JSON/RAW parameters, malformed JSON will cause parsing errors. Validate JSON syntax carefully.
  • Limit exceeded: The API limits the maximum number of users returned per request (max 100). Use "Return All" to paginate or retrieve all users.
  • Export issues: If exporting, ensure the binary property name does not conflict with existing properties and that the file name is valid.
  • Filter and query errors: Incorrect filter or query parameters may result in empty responses or API errors. Verify parameter correctness and supported fields.
  • Continue On Fail: If enabled, errors during execution will be captured in the output instead of stopping the workflow.

Links and References

Discussion