Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API to update a specific field within a collection. It allows users to modify metadata, schema, and type information of a field identified by its unique name in a given collection. This operation is useful when you need to programmatically adjust the structure or properties of fields in your Directus-managed data collections without manually editing them through the Directus interface.

Common scenarios:

  • Updating the data type of a field after initial creation.
  • Modifying the JSON metadata or schema associated with a field to change validation rules or UI presentation.
  • Automating schema changes as part of a deployment or migration workflow.

Practical example:
You have a collection named "articles" with a field "author_id" initially set as an integer. You want to update this field to a UUID type to better align with your user IDs. Using this node, you specify the collection "articles", select the "author_id" field, and set the new type to "UUID". The node sends the update request to Directus, applying the change seamlessly.

Properties

Name Meaning
Field Unique name of the field to update. The field name must be unique within the specified collection.
Collection The name of the collection that contains the field to update.
JSON/RAW Parameters Boolean flag indicating whether the body parameters should be provided via a structured UI (key-value pairs) or as raw JSON input.
Body Parameters When JSON/RAW Parameters is enabled, this property accepts the full body parameters as JSON or raw text for the update request.
Update Fields When JSON/RAW Parameters is disabled, this collection allows specifying individual update properties:
- Meta (JSON) JSON object representing meta information about the field.
- Schema (JSON) JSON object defining the schema details of the field.
- Type The Directus-specific data type to cast the field values. Options include:
• Big Integer
• Boolean
• CSV (array of strings)
• DateTime
• Date
• Decimal
• Field Group
• Float
• Hash
• Integer
• JSON
• M2A (Many to Any relationship)
• M2M (Many to Many relationship)
• M2O (Many to One relationship)
• Multiple Files
• O2M (One to Many relationship)
• Presentation
• Single File
• String
• Text
• Timestamp
• Time
• UUID

Output

The node outputs the updated field's data as a JSON object under the json property. This output reflects the response from the Directus API after successfully updating the field, typically including the updated field attributes such as its name, type, meta, and schema.

No binary data output is produced by this operation.

Dependencies

  • Requires a valid connection to a Directus instance via an API key credential configured in n8n.
  • The node uses the Directus REST API endpoints for fields management.
  • Proper permissions on the Directus API are necessary to perform update operations on fields.

Troubleshooting

  • Invalid Field or Collection Name: If the specified field or collection does not exist, the API will return an error. Verify that the names are correct and exist in your Directus project.
  • Malformed JSON Input: When using JSON/RAW Parameters, ensure that the JSON syntax is valid. Invalid JSON will cause parsing errors.
  • Insufficient Permissions: The API user must have rights to update fields; otherwise, permission denied errors will occur.
  • Unsupported Type Changes: Some type changes may not be allowed depending on the current state or constraints of the field. Review Directus documentation for valid type transitions.
  • Network or Authentication Errors: Ensure the API credentials are correctly configured and the Directus server is reachable.

Links and References

Discussion