Directus (flagbit) icon

Directus (flagbit)

Consume Directus API

Overview

This node is designed to create a new collection in a Directus system. Collections in Directus represent database tables or entities, and creating a collection allows users to define a new structured data set within the system. This node is useful for automating the setup of new content types or data structures programmatically.

Common scenarios include:

  • Automating the creation of new content types during deployment or setup.
  • Dynamically generating collections based on external inputs or configurations.
  • Managing schema changes as part of an integration workflow.

For example, you might use this node to create a "products" collection with specific fields and display settings, enabling your application to start storing product data immediately.

Properties

Name Meaning
Collection Unique name of the collection to be created (e.g., "articles", "products").
JSON/RAW Parameters Whether to provide the body parameters as a JSON/RAW string or via UI key-value pairs.
Body Parameters The body parameters as JSON or RAW input defining the collection properties when JSON/RAW Parameters is true.
Additional Fields Optional additional configuration fields for the collection:
- Archive Field Field name that holds the archive status value.
- Archive App Filter Value used to filter archived items.
- Archive Value Value used to mark items as archived.
- Display Template Text template describing how items from this collection are displayed across the system.
- Fields (JSON) JSON array defining fields to be created within the collection, specifying their properties such as type, validation, etc.
- Hidden Boolean indicating if the collection should be hidden from navigation in the admin app.
- Icon Name of a Google Material Design icon assigned to the collection for UI representation.
- Note A descriptive note about the collection.
- Singleton Boolean indicating if the collection is treated as a single object rather than multiple entries.
- Sort Field Field name used for sorting items in the collection.
- Translation Key-value pairs for localizing the collection's name in different languages in the admin app.
- Unarchive Value Value used to mark items as unarchived or active.

Output

The node outputs JSON data representing the newly created collection object as returned by the Directus API. This typically includes metadata about the collection such as its unique identifier, name, fields, and configuration settings.

If binary data were involved (not indicated here), it would represent file attachments or media related to the collection, but this node focuses on JSON metadata only.

Dependencies

  • Requires access to a Directus instance with appropriate permissions to create collections.
  • Needs an API authentication token or API key credential configured in n8n to authorize requests.
  • The node depends on internal methods and routing logic bundled in the source code, which handle communication with the Directus API.

Troubleshooting

  • Permission errors: Ensure the API token has rights to create collections; otherwise, the request will fail with authorization errors.
  • Invalid JSON: When using JSON/RAW parameters, malformed JSON will cause parsing errors. Validate JSON syntax before execution.
  • Duplicate collection names: Attempting to create a collection with a name that already exists may result in conflict errors.
  • Missing required fields: The "Collection" name is mandatory; omitting it will cause validation errors.
  • Field definitions: Incorrectly formatted field objects in the "Fields (JSON)" property can cause API rejection.

Links and References

Discussion