Actions109
- Collections Actions
- Activity Actions
- Assets Actions
- Authentication 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
The Directus (DrWade) n8n node for the resource Relations with the operation Create allows you to create a new relation between collections in a Directus project. This is useful when you want to define or automate the creation of relationships (such as one-to-one, one-to-many, or many-to-many) between different data collections within your Directus instance.
Common scenarios:
- Automating the setup of new relations during project initialization.
- Programmatically managing schema changes across environments.
- Integrating Directus schema management into CI/CD pipelines.
Practical example:
Suppose you have an "articles" collection and a "directus_files" collection, and you want to relate an article's "featured_image" field to a file. This node can automate the creation of that relation.
Properties
| Name | Type | Meaning |
|---|---|---|
| Data (JSON) | json | A partial relation object. This should include details such as the source collection, field, related collection, and other relation settings. |
Output
- The output will be a JSON object representing the created relation as returned by the Directus API.
- The structure typically includes fields like
collection,field,related_collection, and other metadata describing the relation. - Example output:
{
"collection": "articles",
"field": "featured_image",
"related_collection": "directus_files",
// ...other relation properties
}
- If an error occurs and "Continue On Fail" is enabled, the output will contain an
errorfield with the error message.
Dependencies
- Directus API: Requires access to a running Directus instance.
- API Credentials: You must configure the
directusApicredentials in n8n for authentication.
Troubleshooting
Common issues:
- Invalid JSON in Data (JSON): If the input is not valid JSON, the node will throw a parsing error. Ensure your JSON is correctly formatted.
- Missing required fields: The Directus API expects certain fields in the relation object (e.g.,
collection,field,related_collection). Omitting these may result in API errors. - Insufficient permissions: The API key/user used must have permission to manage schema/relations in Directus.
Error messages:
"Unexpected token ... in JSON": Indicates malformed JSON in the Data (JSON) property."Request failed with status code 4xx/5xx": Indicates an issue with the Directus API request, such as missing fields or lack of permissions.
How to resolve:
- Double-check your JSON syntax and required fields.
- Verify your Directus user has appropriate permissions.
- Check the Directus API documentation for the expected relation object structure.