Directus icon

Directus

Consume Directus API

Overview

The node interacts with the "Files" resource of the Directus API, specifically supporting the List operation. It retrieves a list of files stored in a Directus instance, allowing users to fetch metadata and details about these files.

This node is beneficial when you want to automate workflows involving file management in Directus, such as:

  • Fetching all files or a subset based on filters for further processing.
  • Exporting file lists in various formats (JSON, CSV, XML).
  • Integrating file metadata retrieval into larger automation pipelines.

For example, you could use this node to get all image files uploaded to your Directus project, then process or move them elsewhere automatically.

Properties

Name Meaning
Return All Boolean flag to return all results or limit the number of returned files.
Limit Number specifying the maximum number of files to return if "Return All" is false. Range: 1 to 100.
Split Into Items Boolean indicating whether to output each file as a separate item or as a single array.
JSON/RAW Parameters Boolean to choose between setting query parameters via UI fields or providing raw JSON input.
Query Parameters JSON object representing query parameters for filtering, sorting, etc., used if "JSON/RAW Parameters" is true.
Additional Fields Collection of optional additional query parameters including:
- Aggregate functions (count, sum, average, min, max, distinct variants) applied on specified fields.
- Binary Property for Export Data: name of the binary property to store exported data.
- Deep (JSON): nested relational dataset query parameters.
- Export: format to save API response to a file; options are JSON, CSV, XML.
- Fields: specify which fields to return in the response.
- File Name for Export Data: base name for exported file without extension.
- Filter (JSON): conditions to filter items in the collection.
- Group By: field(s) to group aggregation results by.
- Meta: metadata to include in the response.
- Offset: number of items to skip when fetching data.
- Search: search query string to filter items containing the query in any field.
- Sort: CSV string defining sort order of returned items; prefix with "-" for descending, "?" for random.

Output

  • The output json field contains the list of files retrieved from the Directus API.
  • If "Split Into Items" is enabled, each file is output as an individual item; otherwise, all files are output as a single array.
  • When the "Export" option is selected, the API response is saved as a binary file in the specified format (JSON, CSV, or XML). This binary data is available under the configured binary property name (default "data"), with appropriate filename and MIME type set.
  • The structure of each file object corresponds to the Directus file metadata schema, typically including properties like id, filename, title, type, size, url, and other metadata fields.

Dependencies

  • Requires connection to a Directus instance via an API key credential (configured in n8n credentials).
  • Uses Directus REST API endpoints for files (GET /files).
  • No additional external dependencies beyond standard HTTP requests to the Directus API.

Troubleshooting

  • Common Issues:

    • Authentication errors due to invalid or missing API credentials.
    • Exceeding API rate limits or permissions restricting access to files.
    • Malformed JSON input when using raw JSON parameters.
    • Incorrect field names or aggregation function parameters causing API errors.
  • Error Messages:

    • Errors returned from the Directus API will be propagated, e.g., "Unauthorized", "Not Found", or validation errors.
    • JSON parsing errors if raw JSON inputs are malformed.
  • Resolutions:

    • Verify API credentials and permissions in Directus.
    • Ensure JSON parameters are valid JSON strings.
    • Use the "Return All" and "Limit" settings appropriately to avoid large payloads.
    • Check field names and aggregation function options against Directus documentation.

Links and References

Discussion