Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Directus (DrWade) n8n node with Resource Collections and Operation Create allows you to create a new collection in your Directus instance. This is useful for automating the setup of new data structures within Directus, such as when onboarding new projects, dynamically generating content types, or programmatically managing schema changes.

Practical scenarios:

  • Automatically creating collections for new clients or projects.
  • Setting up initial database schemas as part of deployment pipelines.
  • Integrating external systems that need to define their own data structures in Directus.

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 true.
Additional Fields Collection Optional extra settings for the collection. Only used if "JSON/RAW Parameters" is false. Includes:
- Archive Field
- Archive App Filter
- Archive Value
- Display Template
- Fields (JSON)
- Hidden
- Icon
- Note
- Singleton
- Sort Field
- Translation
- Unarchive Value

Additional Fields Breakdown

  • Archive Field: Field holding the archive value.
  • Archive App Filter: Value used for filtering archived items.
  • Archive Value: Value to mark items as archived.
  • Display Template: How items from this collection are shown across the system.
  • Fields (JSON): Array of field definitions to create during collection creation (fields object documentation).
  • Hidden: Whether the collection is hidden from navigation in the admin app.
  • Icon: Google Material Design icon assigned to the collection.
  • Note: Description or note about the collection.
  • Singleton: Whether the collection is treated as a single object.
  • Sort Field: Default sort field for the collection.
  • Translation: Key-value pairs for displaying the collection's name in different languages.
  • Unarchive Value: Value to unarchive items.

Output

  • The output will be a json object representing the newly created collection as returned by the Directus API.
  • The structure typically includes details such as the collection name, meta information, and any additional configuration provided.
  • Example output:
    {
      "collection": "articles",
      "meta": {
        "icon": "people",
        "note": "A note describing the collection.",
        ...
      },
      "schema": { ... },
      ...
    }
    
  • If an error occurs and "Continue On Fail" is enabled, the output will contain an error property with the error message.

Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.
  • No additional environment variables are required beyond those needed for Directus connectivity.

Troubleshooting

Common issues:

  • Missing or invalid collection name: Ensure the "Collection" field is filled and unique.
  • Invalid JSON in Body Parameters: If using JSON/RAW mode, ensure your JSON is valid.
  • Insufficient permissions: The API user must have permission to create collections.
  • Field definition errors: If providing custom fields, ensure they match the Directus fields object specification.

Error messages:

  • "error": "Request failed with status code 401": Check your API credentials.
  • "error": "Collection already exists": Use a unique collection name.
  • "error": "Invalid field definition": Review your "Fields (JSON)" input.

Links and References

Discussion