Actions109
- Activity Actions
- Assets Actions
- Authentication Actions
- Collections Actions
- Extensions Actions
- Fields Actions
- Files Actions
- Folders Actions
- Items Actions
- Permissions Actions
- Presets Actions
- Relations Actions
- Revisions Actions
- Roles Actions
- Settings Actions
- Users Actions
- Utilities Actions
- Webhooks Actions
Overview
This node integrates with the Directus API to manage relations between collections in a Directus project. Specifically, the "Relations" resource with the "Create" operation allows users to create new relation objects that define how different collections relate to each other.
Use cases include:
- Defining relationships such as one-to-many or many-to-many between database tables (collections).
- Automating schema updates by programmatically adding relations.
- Managing complex data models where collections are interconnected.
For example, you might create a relation linking an "articles" collection's "featured_image" field to the "directus_files" collection to associate images with articles.
Properties
| Name | Meaning |
|---|---|
| Data (JSON) | A partial JSON object representing the relation to create. This should follow the Directus relation object structure, including fields like collection, field, and related_collection. |
The property expects a JSON input describing the relation details, for example:
{
"collection": "articles",
"field": "featured_image",
"related_collection": "directus_files"
}
Output
The output is a JSON object representing the newly created relation as returned by the Directus API. It contains all properties of the relation object, confirming the creation and providing details such as IDs and metadata.
No binary data output is involved in this operation.
Dependencies
- Requires a valid connection to a Directus instance via an API key credential.
- The node uses the Directus REST API endpoint
/relationswith HTTP POST method. - Proper permissions on the Directus project to create relations are necessary.
Troubleshooting
- Invalid JSON Input: If the "Data (JSON)" property contains malformed JSON, the node will throw a parsing error. Ensure the JSON is well-formed.
- API Authentication Errors: If the API key or credentials are invalid or missing, authentication errors will occur. Verify the API key configuration.
- Permission Denied: Insufficient permissions to create relations in Directus will result in authorization errors. Check user roles and permissions.
- Missing Required Fields: The relation object must include required fields like
collection,field, andrelated_collection. Omitting these may cause API validation errors. - Directus API Errors: Any errors returned from the Directus API (e.g., conflicts, invalid relation definitions) will be passed through. Review the error message for guidance.