Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Relations → Update

AI-generated

Overview

The Directus (DrWade) n8n node for the resource Relations with the operation Update allows you to update an existing relation between collections in a Directus project. This is useful when you need to modify how two collections are related, such as changing the metadata or configuration of a relational field (e.g., updating a foreign key relationship).

Common scenarios:

  • Adjusting the configuration of a many-to-one or one-to-many relationship after initial setup.
  • Updating relation metadata, such as labels, junction collection, or other advanced settings.
  • Automating schema changes across environments.

Practical example:
Suppose you have a books collection with an author field relating to an authors collection. If you want to change the relation's metadata (like making it a different type of relation or updating its options), you can use this node to PATCH the relation object.


Properties

Name Type Meaning
Collection options Unique name of the parent collection. Select the collection where the relation exists.
Field options Name of the field that holds the related primary key. This matches the column in the DB.
Data (JSON) json A partial relation object. Contains the properties to update for the relation.

Output

  • The output will be a single JSON object representing the updated relation.
  • The structure of the output matches the Directus relation object, including any fields you updated and their new values.

Example output:

{
  "collection": "books",
  "field": "author",
  "meta": {
    "one_field": "articles"
    // ...other updated meta fields
  },
  // ...other relation properties
}

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.
  • Malformed Data (JSON): If the Data (JSON) property is not valid JSON or does not match the expected structure, the request will fail.
  • Insufficient Permissions: The API user must have permission to update relations in Directus.

Error messages and resolutions:

  • "Cannot find collection/field": Double-check the collection and field names.
  • "Invalid relation object": Ensure your JSON follows the Directus relation object schema.
  • "Unauthorized": Verify your API credentials and permissions.

Links and References

Discussion