Directus (denkhaus) icon

Directus (denkhaus)

Consume Directus API

Overview

This n8n node is designed to create a new relation in a Directus project. A "relation" in Directus defines how two collections (tables) are linked, such as setting up a one-to-many or many-to-many relationship between data entities. This node is useful when you need to programmatically establish or update the schema of your Directus instance, especially during automated workflows for project setup, migrations, or dynamic schema management.

Practical examples:

  • Automatically linking an "articles" collection to a "files" collection via a "featured_image" field.
  • Setting up relationships between users and roles during onboarding processes.
  • Creating custom relations as part of a deployment pipeline.

Properties

Name Meaning
Data (JSON) A partial relation object. This should be a JSON object specifying details like collection, field, and related_collection. Example:

json { "collection": "articles", "field": "featured_image", "related_collection": "directus_files" }

Output

The output will contain the created relation object in JSON format, reflecting the structure defined by the Directus API for relation objects. The fields typically include information about the collections, fields, and type of relation established.

Example output:

{
  "collection": "articles",
  "field": "featured_image",
  "related_collection": "directus_files",
  // ...other relation properties as returned by Directus
}

Dependencies

  • Directus API: Requires access to a Directus instance with appropriate permissions to create relations.
  • Authentication: An API key or valid credentials configured in n8n for the Directus node.

Troubleshooting

  • Invalid JSON: If the "Data (JSON)" property is not valid JSON, the node will fail. Ensure the input is properly formatted.
  • Missing Required Fields: Omitting required fields like collection, field, or related_collection may result in errors from the Directus API.
  • Permission Denied: If the API credentials lack permission to modify schema or create relations, the operation will fail with an authorization error.
  • Relation Already Exists: Attempting to create a duplicate relation may result in a conflict error from Directus.

Links and References

Discussion