Directus (denkhaus) icon

Directus (denkhaus)

Consume Directus API

Overview

The "Create Multiple" operation for the "Item" resource in this custom n8n node allows users to create multiple items at once within a specified collection. This is particularly useful when you need to batch-insert several records into a Directus collection, such as importing articles, products, or any other data objects managed by Directus.

Common scenarios:

  • Bulk uploading new content (e.g., articles, products) to a Directus-managed database.
  • Migrating data from another system into Directus.
  • Automating the creation of multiple entries based on external triggers or workflows.

Practical example:
You have a list of blog posts in JSON format and want to add them all to your "articles" collection in Directus with a single workflow execution.

Properties

Name Meaning
Collection Name The unique name of the parent collection where the items will be created. Options are loaded dynamically.
Data (JSON) An array of partial item objects in JSON format. Each object represents an item to be created.

Output

The output will be a json field containing the result of the bulk creation operation. Typically, this includes:

  • An array of the created item objects, each reflecting the structure defined by the target collection in Directus.
  • Each object may include fields such as IDs, timestamps, and any data provided in the input.

Example output:

[
  {
    "id": 1,
    "title": "Hello world!",
    "body": "This is our first article"
  },
  {
    "id": 2,
    "title": "Hello again, world!",
    "body": "This is our second article"
  }
]

Note: The actual fields depend on your Directus collection schema.

Dependencies

  • Directus API: Requires access to a Directus instance.
  • API Key/Authentication: You must configure authentication credentials for the Directus API in n8n.
  • n8n Configuration: Ensure that the node is properly configured with the correct Directus API endpoint and credentials.

Troubleshooting

Common issues:

  • Invalid Collection Name: If the collection name does not exist, the operation will fail. Double-check the spelling and existence of the collection.
  • Malformed JSON: If the "Data (JSON)" property contains invalid JSON, the node will throw a parsing error. Always validate your JSON before submitting.
  • Missing Required Fields: If any required fields for the collection are missing in the item objects, Directus will return an error specifying which fields are missing.
  • Authentication Errors: If API credentials are incorrect or missing, you may receive authentication or authorization errors.

Error messages and resolutions:

  • "Collection not found": Verify the collection name and ensure it exists in Directus.
  • "Invalid JSON": Use a JSON validator to check your input.
  • "Missing required field: <field_name>": Add the required field to each item object in your input array.
  • "Unauthorized": Check your API credentials and permissions.

Links and References

Discussion