Directus icon

Directus

Consume Directus API

Overview

The Directus - Relation: List operation retrieves a list of all relations (relationships between collections) for a specified collection in a Directus instance. This is useful for understanding how different collections are linked together, which is essential when designing data models, building integrations, or generating documentation.

Common scenarios:

  • Discovering all relationships for a given collection to inform API usage or UI design.
  • Automating schema analysis or migration tasks.
  • Building tools that visualize or document the structure of your Directus project.

Practical example:
If you have a collection called articles, using this operation will return all the relations (e.g., one-to-many, many-to-many) that involve the articles collection.


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 not enabled, the output is a single item with an array of relation objects.

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

  • collection: Name of the collection.
  • field: Field name representing the relation.
  • related_collection: The related collection's name.
  • meta: Metadata about the relation (type, junction info, etc.).

Example output (when Split Into Items is false):

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

Example output (when Split Into Items is true):

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

(One item per relation.)


Dependencies

  • Directus API: Requires access to a Directus instance.
  • API Credentials: You must configure the node with valid Directus API credentials (directusApi).

Troubleshooting

Common issues:

  • Invalid Collection Name: If the specified collection does not exist, the node may throw an error indicating the collection was not found.
  • Authentication Errors: Invalid or missing API credentials will result in authentication failures.
  • Permissions: The API user must have permission to read schema/relations information for the target collection.

Error messages and resolutions:

  • "Collection not found": Check the spelling of the collection name and ensure it exists in Directus.
  • "Unauthorized" or "Forbidden": Verify that the API credentials are correct and have sufficient permissions.
  • "Network Error": Ensure the Directus instance is reachable from n8n.

Links and References

Discussion