Directus (denkhaus) icon

Directus (denkhaus)

Consume Directus API

Overview

This node updates a relation in a Directus database. It is designed to modify the relationship between collections (tables) by updating the field that holds the related primary key. This is useful when you need to change how two collections are linked, such as updating the author of an article or changing the category of a product.

Common scenarios:

  • Updating the author of a book in a library management system.
  • Changing the assigned user for a task in a project management tool.
  • Modifying the linked category for a product in an e-commerce platform.

Practical example:
If you have a collection called books and want to update which author is related to a specific book, you would use this node to specify the new author.

Properties

Name Meaning
Field Name Name of the field that holds the related primary key. This matches the column name in the database. Options are dynamically loaded based on the selected Collection Name.
Data (JSON) A partial relation object in JSON format. This contains the data to update in the relation, such as specifying the new related record.
Collection Name Unique name of the parent collection. Options are dynamically loaded from your Directus instance.

Output

The output will be a JSON object representing the updated relation. The structure will typically include the fields of the relation object as defined in the Directus API, reflecting the changes made by the update operation.

Example output:

{
  "collection": "books",
  "field": "author",
  "meta": {
    "one_field": "articles"
  }
}

Note: The actual output fields depend on the Directus relation object schema.

Dependencies

  • Requires access to a Directus instance.
  • May require authentication credentials (API key or login) configured in n8n.
  • The node depends on the correct setup of collections and relations in your Directus database.

Troubleshooting

  • Invalid Field Name: If the specified field does not exist in the selected collection, the node may throw an error. Ensure the field name matches exactly with your database schema.
  • Malformed JSON: If the Data (JSON) property is not valid JSON, the node will fail. Always validate your JSON before submitting.
  • Permission Denied: If the API credentials do not have permission to update relations, you may receive an authorization error. Check your Directus user permissions.
  • Missing Required Fields: If required properties are missing, the node will not execute successfully. Make sure all required fields are filled.

Links and References

Discussion