Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Directus (DrWade) n8n node for the resource Relations with the operation List allows you to retrieve all relation definitions for a specific collection in your Directus instance. This is useful when you want to programmatically inspect or process the relationships (such as one-to-many, many-to-many, etc.) defined between collections in your Directus data model.

Common scenarios:

  • Automating documentation of your data model by extracting and listing all relations for a given collection.
  • Building dynamic workflows that adapt based on the structure of your Directus schema.
  • Validating or auditing the relationships in your database before performing migrations or updates.

Practical example:
Suppose you have a collection called articles and you want to list all its relations (e.g., which other collections it references or is referenced by). This operation will return all such relations, which can then be used in further workflow steps.


Properties

Name Type Meaning
Collection options Unique name of the parent collection whose relations you want to list.
Split Into Items boolean If enabled, outputs each relation as a separate item; otherwise, returns an array of relations in a single item.

Output

  • The output is provided in the json field.
  • If Split Into Items is enabled, each output item contains a single relation object.
  • If Split Into Items is disabled, the output is a single item containing an array of relation objects.

Structure of a relation object:
Each relation object typically includes details such as:

  • collection: The parent collection name.
  • field: The field in the collection that defines the relation.
  • related_collection: The related collection's name.
  • meta: Metadata about the relation (type, junction table info, etc.).

Example output (with Split Into Items = false):

{
  "json": [
    {
      "collection": "articles",
      "field": "author",
      "related_collection": "users",
      "meta": { /* ... */ }
    },
    {
      "collection": "articles",
      "field": "category",
      "related_collection": "categories",
      "meta": { /* ... */ }
    }
  ]
}

Example output (with Split Into Items = true):

{
  "json": {
    "collection": "articles",
    "field": "author",
    "related_collection": "users",
    "meta": { /* ... */ }
  }
}

(One item per relation.)


Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.

Troubleshooting

Common issues:

  • Invalid Collection Name: If the specified collection does not exist, the node will throw an error. Double-check the collection name.
  • Insufficient Permissions: The API user must have permission to read schema/relations in Directus.
  • Network/API Errors: Connectivity issues or incorrect API URL/credentials will result in errors.

Error messages and resolutions:

  • "Collection not found": Ensure the collection exists in Directus.
  • "Unauthorized" or "Forbidden": Check your API credentials and permissions.
  • "Cannot read property 'data' of undefined": Indicates an unexpected API response; verify your Directus instance is healthy and reachable.

Links and References


Discussion