Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Directus (DrWade) n8n node for the "Relations" resource, "List All" operation, retrieves all relation definitions from a Directus instance. This is useful for administrators or developers who need to programmatically inspect or audit the relationships between collections in their Directus project.

Common scenarios:

  • Generating documentation of data models.
  • Building dynamic UIs that reflect available relations.
  • Automating schema audits or migrations.

Practical example:
You might use this node in an automation workflow to fetch all relations, filter them, and then notify your team if new relations are added or existing ones are changed.


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 relation objects to return. Only used if "Return All" is false. Accepts values from 1 to 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 you to specify query parameters as raw JSON instead of using the UI fields.
Query Parameters json Custom query parameters as a flat JSON object. Only shown if "JSON/RAW Parameters" is enabled.
Additional Fields collection Extra options for filtering, aggregation, export, and more. See below for details.

Additional Fields options include:

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

Output

  • json:

    • If "Split Into Items" is enabled, each output item contains a single relation definition as a JSON object.
    • Otherwise, the output is a single item with a json field containing an array of relation objects.
  • binary (optional):

    • If "Export" is set (csv, json, xml), the exported file is attached to the output under the specified binary property name.

Example output (when not split into items):

{
  "json": [
    {
      "collection": "posts",
      "field": "author",
      "related_collection": "users",
      // ...other relation properties
    },
    ...
  ]
}

Example output (with "Split Into Items"):

{
  "json": {
    "collection": "posts",
    "field": "author",
    "related_collection": "users"
    // ...other relation properties
  }
}

If exporting, the binary property will contain the file data.


Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the "directusApi" credentials in n8n with appropriate permissions to read relations.
  • n8n: No additional configuration required beyond standard credential setup.

Troubleshooting

Common issues:

  • Authentication errors: Ensure your API credentials are correct and have permission to access the "relations" endpoint.
  • Empty results: If no relations exist, the output will be an empty array.
  • Invalid JSON in parameters: When using "JSON/RAW Parameters", ensure your JSON is valid, or the node may throw a parsing error.
  • Export errors: If "Export" is selected but the API response is not compatible, the binary output may be empty or malformed.

Error messages:

  • "error": "Unexpected token ...": Indicates invalid JSON input in one of the parameters.
  • "error": "Request failed with status code 401": Authentication issue—check your credentials.
  • "error": "Request failed with status code 403": Permission issue—ensure your user has access to view relations.

Links and References


Discussion