Directus icon

Directus

Consume Directus API

Overview

The Directus node for n8n, when configured with the Resource: Folder and Operation: List, retrieves a list of folders from a Directus instance. This operation is highly customizable, allowing you to control pagination, filtering, sorting, aggregation, and export options.

Common scenarios:

  • Listing all folders in your Directus project for further processing.
  • Filtering or searching folders based on specific criteria.
  • Exporting folder data as CSV, JSON, or XML files for reporting or backup.
  • Integrating folder metadata into other workflows.

Practical examples:

  • Fetch all folders and split them into individual items for downstream processing.
  • Retrieve only a limited number of folders matching a search term.
  • Export the entire folder structure as a CSV file for archival purposes.

Properties

Name Type Meaning
Return All boolean If enabled, returns all available folders. If disabled, limits the number of returned folders according to the "Limit" property.
Limit number The maximum number of folders to return (only shown if "Return All" is false). Must be between 1 and 100.
Split Into Items boolean If enabled, outputs each folder as a separate item; otherwise, returns all folders in a single item.
JSON/RAW Parameters boolean If enabled, allows setting query parameters via a raw JSON object instead of using the UI fields.
Query Parameters json Custom query parameters as a flat JSON object (only visible if "JSON/RAW Parameters" is true).
Additional Fields collection A set of advanced options for customizing the request, including:
- Aggregate: Apply aggregation functions (count, sum, avg, etc.) on specified fields.
- Binary Property for Export Data: Name of the binary property to store exported data.
- Deep (JSON): Nested query parameters for relational datasets.
- Export: Export format (csv, json, xml).
- Fields: Specify which fields to return.
- File Name for Export Data: File name for exported data (without extension).
- Filter (JSON): Filter conditions as JSON.
- Group By: Group results by one or more fields.
- Meta: Metadata to include in the response.
- Offset: Number of items to skip.
- Search: Search string to filter folders.
- Sort: Sorting instructions for the result set.

Output

  • Standard Output:

    • If "Split Into Items" is enabled, each output item contains a json field representing a single folder object.
    • If not, the json field contains an array or object with all retrieved folders.
  • Export/Binary Output:

    • If the "Export" option is used, the output will also include a binary field containing the exported data (CSV, JSON, or XML) under the specified binary property name.

Example output (single item):

{
  "json": {
    "id": "abc123",
    "name": "My Folder",
    "parent": null,
    // ...other folder properties
  }
}

Example output (split into items):

[
  { "json": { "id": "abc123", "name": "Folder 1" } },
  { "json": { "id": "def456", "name": "Folder 2" } }
]

Example output (with export):

{
  "json": { /* folder data */ },
  "binary": {
    "data": {
      "data": "<Buffer ...>",
      "fileName": "export.csv",
      "mimeType": "text/csv"
    }
  }
}

Dependencies

  • External Service: Requires access to a running Directus instance.
  • Authentication: Needs valid Directus API credentials configured in n8n (credential type: directusApi).
  • Environment: No special environment variables required beyond standard n8n and Directus setup.

Troubleshooting

Common issues:

  • Invalid Credentials: If the Directus API credentials are incorrect or missing, authentication errors will occur.
  • API Limits: If "Limit" exceeds allowed values, or if "Return All" is used on very large datasets, performance may degrade.
  • Malformed JSON: When using "Query Parameters" or "Filter (JSON)", ensure the input is valid JSON; otherwise, parsing errors will occur.
  • Export Errors: If exporting, ensure the binary property name does not conflict with existing properties.

Error messages and resolutions:

  • "error": "Unexpected token ... in JSON": Check that any JSON input (e.g., filters, query parameters) is properly formatted.
  • "error": "Request failed with status code 401": Verify your Directus API credentials.
  • "error": "limit must be between 1 and 100": Adjust the "Limit" property to be within the allowed range.

Links and References

Discussion