Directus icon

Directus

Consume Directus API

Overview

This node interacts with the Directus API to manage and retrieve data related to "Relations" within a Directus project. Specifically, the "List All" operation fetches all relation records from the Directus backend.

Use cases include:

  • Retrieving all relational metadata between collections in your Directus instance.
  • Exporting relations data for analysis or migration.
  • Filtering and sorting relations based on custom query parameters.

Practical example:

  • You want to get a complete list of all relations defined in your Directus project to audit or document how collections are linked.
  • You need to export relations data as CSV or JSON for integration with other systems.

Properties

Name Meaning
Return All Boolean flag to return all results or limit the number of returned items.
Limit Number specifying the maximum number of objects to return when "Return All" is false (minimum 1, maximum 100).
Split Into Items Boolean indicating whether to output each element of the returned array as a separate item.
JSON/RAW Parameters Boolean to choose if query parameters should be set via UI key-value pairs or raw JSON input.
Query Parameters JSON object representing query parameters as a flat object, used when "JSON/RAW Parameters" is true.
Additional Fields Collection of optional fields to customize the request, including:
- Aggregate functions (count, sum, average, min, max, etc.) applied on specified fields.
- Binary property name for export data.
- Deep JSON for nested relational queries.
- Export format (json, csv, xml) to save API response to a file.
- Fields to control which fields are returned.
- File name for exported data.
- Filter conditions as JSON.
- Group By field(s) for aggregation.
- Meta information to return.
- Offset to skip items.
- Search string to filter items.
- Sort order as CSV of fields.

Output

The node outputs JSON data representing the list of relations retrieved from the Directus API.

  • If "Split Into Items" is enabled, each relation object is output as an individual item.
  • If an export option is selected (json, csv, xml), the API response is also saved as binary data under the specified binary property name, with the given file name and appropriate file extension.
  • The JSON structure corresponds directly to the Directus relations data schema, typically including fields such as collection names, fields involved in the relation, and relation types.

Dependencies

  • Requires a valid connection to a Directus API endpoint.
  • Needs an API authentication credential configured in n8n to authorize requests.
  • Uses internal helper methods to make HTTP requests to Directus REST endpoints.
  • Supports exporting data as files, requiring n8n's binary data handling capabilities.

Troubleshooting

  • Authentication errors: Ensure the API key or token credential is correctly configured and has sufficient permissions to access relations.
  • Invalid JSON in parameters: When using JSON/RAW parameters, ensure the JSON syntax is correct to avoid parsing errors.
  • Limit exceeded: The "Limit" property must be between 1 and 100; setting values outside this range may cause errors.
  • Export issues: If exporting data, verify that the binary property name and file name are valid strings.
  • API errors: Any error messages returned by the Directus API will be included in the output if "Continue On Fail" is enabled; otherwise, they will stop execution.

Links and References

Discussion