Directus icon

Directus

Consume Directus API

Overview

The Directus - Relation: Get operation retrieves detailed information about a specific relation (foreign key relationship) between collections in a Directus project. This is useful for understanding how two collections are linked, which fields are involved, and the configuration of that relationship.

Common scenarios:

  • Inspecting the structure of your data model.
  • Building dynamic UIs or automations that depend on collection relationships.
  • Debugging or documenting the schema of your Directus instance.

Practical example:
Suppose you have a books collection with an author field that relates to an authors collection. Using this node, you can fetch all metadata about the author relation in the books collection.


Properties

Name Type Meaning
Collection options Unique name of the parent collection. Select the collection where the relation is defined.
Field options Name of the field holding the related primary key. This matches the column name in the DB.

Output

The output will be a JSON object containing the details of the specified relation. The structure typically includes:

{
  "collection": "books",
  "field": "author",
  "related_collection": "authors",
  "meta": { /* additional metadata */ },
  // ...other relation properties as provided by Directus API
}
  • collection: The parent collection name.
  • field: The field in the parent collection that holds the relation.
  • related_collection: The target/related collection.
  • meta: Additional metadata about the relation (e.g., type, constraints, etc.).
  • Other fields may be present depending on the Directus API response.

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 or field: If the specified collection or field does not exist, the node will throw an error.
  • Insufficient permissions: The API user must have permission to read schema/relations.
  • Network/API errors: Connectivity issues or incorrect API URL/credentials will cause failures.

Error messages and resolutions:

  • "Collection not found": Double-check the collection name.
  • "Field not found": Ensure the field exists and is a relation.
  • "Unauthorized": Verify your API credentials and permissions.

Links and References

Discussion