Directus (flagbit) icon

Directus (flagbit)

Consume Directus API

Overview

The node is designed to update a relation in a Directus data platform. Relations in Directus define how collections (tables) are linked together, typically through foreign keys. This node allows users to modify an existing relation by specifying the collection it belongs to, the field that holds the related primary key, and providing partial JSON data describing the updates to apply to the relation object.

This node is beneficial when managing complex data models where relationships between collections need to be adjusted or corrected without manually editing the database schema. For example, if you want to change metadata on a relation or update how two collections relate, this node provides a programmatic way to do so.

Practical examples:

  • Updating the metadata of a relation between "authors" and "articles" collections.
  • Changing the relational field used for linking two collections.
  • Modifying relation properties such as cardinality or junction table details via JSON input.

Properties

Name Meaning
Collection Name Unique name of the parent collection where the relation exists. Options are dynamically loaded from available collections.
Field Name The name of the field in the collection that holds the related primary key. Matches the column name in the database. Options are dynamically loaded based on the selected collection.
Data (JSON) A partial JSON object representing the relation to update. This follows the structure of a Directus relation object and can include fields like metadata or other relation attributes.

Output

The node outputs JSON data representing the updated relation object after applying the changes. This JSON reflects the current state of the relation in the Directus system, including any modifications made during the update operation.

If the node supports binary data output, it would typically represent files or attachments related to the relation, but based on the provided code and properties, the output is purely JSON.

Dependencies

  • Requires access to a Directus instance with appropriate API credentials to authenticate and authorize relation updates.
  • Needs configuration of API authentication tokens or keys within n8n to connect securely to the Directus API.
  • Dynamic loading of options for collections and relational fields depends on API calls to the Directus backend.

Troubleshooting

  • Common issues:

    • Invalid or missing collection name or field name may cause the update to fail.
    • Malformed JSON in the "Data (JSON)" property can lead to parsing errors.
    • Insufficient permissions on the Directus API user may result in authorization errors.
    • Network connectivity problems can prevent communication with the Directus server.
  • Error messages and resolutions:

    • "Field is required" — Ensure the "Field Name" property is set and corresponds to a valid relational field.
    • "Collection not found" — Verify the collection name is correct and exists in the Directus instance.
    • "Invalid JSON format" — Check the syntax of the JSON input in the "Data (JSON)" property.
    • "Unauthorized" or "Forbidden" — Confirm that the API credentials have sufficient rights to update relations.

Links and References

Discussion