Directus icon

Directus

Consume Directus API

Overview

The Directus node for n8n, when configured with the Resource: Collection and Operation: Create, allows you to create a new collection (table) in your Directus instance. This is useful for dynamically managing your data model from within an n8n workflow—such as automating the setup of new content types, onboarding new projects, or programmatically extending your CMS/database schema.

Practical examples:

  • Automatically creating a new "articles" collection when a new blog is launched.
  • Setting up custom collections for each client in a multi-tenant application.
  • Creating collections with specific fields and metadata based on user input or external triggers.

Properties

Name Type Meaning
Collection String Unique name of the collection to be created (e.g., "articles"). Required unless using JSON/RAW parameters.
JSON/RAW Parameters Boolean If enabled, allows you to provide all body parameters as raw JSON instead of using the UI fields. When true, only the "Body Parameters" field is used.
Body Parameters JSON The full set of body parameters as JSON or RAW. Used only if "JSON/RAW Parameters" is enabled.
Additional Fields Collection Optional settings for the collection, such as archive field, display template, icon, note, singleton status, sort field, translation, and more. Only used if not using JSON/RAW mode.

Additional Fields options include:

  • Archive Field: Field that holds the archive value.
  • Archive App Filter: Value to use for filtering archived items.
  • Archive Value: Value to use to "unarchive" items.
  • Display Template: How items are shown across the system.
  • Fields (JSON): Array of fields to be created in the collection (see fields object documentation).
  • Hidden: Whether the collection is hidden in the admin app.
  • Icon: Google Material Design icon assigned to this collection.
  • Note: Description of the collection.
  • Singleton: Whether the collection is treated as a single object.
  • Sort Field: Field used for sorting.
  • Translation: Key-value pairs for collection names in different languages.
  • Unarchive Value: Value to show the "archived" filter.

Output

  • The output will be a single item with a json property containing the response from the Directus API after creating the collection.
  • The structure of the json output will reflect the newly created collection's details, typically including:
    • collection: The name of the collection.
    • meta: Metadata about the collection (if provided).
    • schema: Schema information, including fields if specified.
    • Other properties as returned by Directus for a collection creation.

Example output:

{
  "collection": "articles",
  "meta": {
    "icon": "people",
    "note": "A collection for articles"
  },
  "schema": {
    "fields": [
      // ...field definitions if provided
    ]
  }
  // ...other Directus response properties
}
  • If there is an error and "Continue On Fail" is enabled, the output will contain an error property with the error message.

Dependencies

  • Directus API: You must have access to a running Directus instance.
  • API Credentials: The node requires valid Directus API credentials (directusApi) configured in n8n.
  • n8n Configuration: No special environment variables beyond standard credential setup.

Troubleshooting

Common issues:

  • Missing required fields: If "Collection" is not provided (and not using JSON/RAW), the request will fail.
  • Invalid JSON: If the JSON in "Body Parameters" or "Fields (JSON)" is malformed, the node will throw a parsing error.
  • Duplicate collection name: Attempting to create a collection with a name that already exists will result in an error from Directus.
  • Insufficient permissions: The API user must have permission to create collections in Directus.

Error messages:

  • "error": "Request failed with status code 400": Usually indicates missing or invalid parameters.
  • "error": "Unexpected token ... in JSON": Indicates malformed JSON in one of the JSON fields.
  • "error": "Collection already exists": The collection name is already taken.

How to resolve:

  • Double-check required fields and ensure all JSON inputs are valid.
  • Ensure the API credentials have sufficient permissions.
  • Use unique collection names.

Links and References

Discussion