Directus icon

Directus

Consume Directus API

Overview

The Directus n8n node, when configured with the Preset resource and the List operation, retrieves a list of preset configurations from a Directus instance. This is useful for automating workflows that need to access or process saved views, filters, or other preset data structures within Directus.

Common scenarios:

  • Fetching all available presets for reporting or synchronization.
  • Exporting presets in various formats (CSV, JSON, XML) for backup or migration.
  • Filtering, sorting, or aggregating preset data for analytics or dashboarding.

Practical examples:

  • Automatically exporting all user-defined presets as a CSV file on a schedule.
  • Integrating Directus presets into another system by fetching and transforming them via n8n.

Properties

Name Type Meaning
Return All boolean If enabled, returns all results; otherwise, limits the number of returned objects according to the "Limit" property.
Limit number The maximum number of presets to return. Only shown if "Return All" is disabled. Accepts values between 1 and 100.
Split Into Items boolean If enabled, outputs each element of the result array as its own item in the n8n workflow.
JSON/RAW Parameters boolean If enabled, allows setting query parameters as raw JSON instead of using the UI fields.
Query Parameters json Custom query parameters as a flat JSON object. Only used if "JSON/RAW Parameters" is enabled.
Additional Fields collection Extra options for filtering, aggregation, export, and more. See below for sub-options.

Additional Fields sub-options:

  • Aggregate: Apply aggregation functions (count, sum, avg, min, max, etc.) to specific fields.
  • Binary Property for Export Data: Name of the binary property to store exported file data.
  • Deep (JSON): Set nested query parameters for relational datasets.
  • Export: Choose to export the API response as a file (json, csv, xml).
  • Fields: Specify which fields to include in the response.
  • File Name for Export Data: File name (without extension) for exported data.
  • Filter (JSON): Filter conditions as JSON.
  • Group By: Group results by specified fields.
  • Meta: Specify metadata to include in the response.
  • Offset: Number of items to skip (for pagination).
  • Search: Search string to filter items.
  • Sort: Sorting instructions (CSV of fields, use minus sign for descending).

Output

  • The output is an array of items, each with a json field containing the preset data.
  • If Split Into Items is enabled, each preset is output as a separate item.
  • If Export is set (to csv, json, or xml), the exported file is attached as binary data under the specified property name (default: data). The json field will still contain the preset data.

Example output structure:

[
  {
    "json": {
      "id": 1,
      "name": "My Preset",
      "user": "user_id",
      // ...other preset fields
    }
  },
  {
    "json": {
      "id": 2,
      "name": "Another Preset",
      // ...
    }
  }
]

If exporting:

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

Dependencies

  • Directus API: Requires a valid Directus API endpoint and credentials (API key or login).
  • n8n Credentials: Must configure the "directusApi" credential in n8n.

Troubleshooting

Common issues:

  • Authentication errors: Ensure your Directus credentials are correct and have permission to access presets.
  • Invalid JSON: When using JSON/RAW parameters, ensure the JSON syntax is valid.
  • Empty results: Check your filters, search, or limit settings; you may be filtering out all results.
  • Export errors: If exporting, ensure the binary property name does not conflict with existing properties.

Error messages:

  • "error": "Unexpected token ...": Indicates invalid JSON input in one of the JSON fields.
  • "error": "Request failed with status code 401": Authentication issue; check credentials.
  • "error": "Field ... does not exist": Aggregation or field selection references a non-existent field.

Links and References

Discussion