Directus icon

Directus

Consume Directus API

Overview

The Directus - Item: Create operation allows you to create a new item (record) in a specified collection within your Directus instance. This is useful for automating the insertion of data into any custom or system collection managed by Directus, such as articles, products, users, etc.

Common scenarios:

  • Adding new content (e.g., blog posts, products) from another system or workflow.
  • Automating data entry based on external triggers (e.g., form submissions, API calls).
  • Integrating with other n8n nodes to enrich or transform data before storing it in Directus.

Example:
Automatically create a new "article" in the "articles" collection when a new row is added to a Google Sheet.


Properties

Name Type Meaning
Collection options Unique name of the parent collection where the item will be created.
Data (JSON) json The partial item object.

Output

  • The output is a json object containing the newly created item's data as returned by the Directus API.
  • The structure of this object depends on the fields defined in your target collection.
  • Example output for an "articles" collection might look like:
{
  "id": 123,
  "title": "Hello world!",
  "body": "This is our first article",
  "date_created": "2024-06-01T12:00:00Z",
  ...
}
  • No binary data is produced by this operation.

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.

Troubleshooting

Common issues:

  • Invalid Collection Name: If the collection does not exist, the API will return an error.
  • Malformed JSON in Data: If the "Data (JSON)" property is not valid JSON, the node will throw a parsing error.
  • Missing Required Fields: If required fields for the collection are missing in the data, Directus will reject the request.
  • Insufficient Permissions: The API credentials used must have permission to create items in the specified collection.

Error messages and resolutions:

  • "Collection not found": Check that the collection name is correct and exists in Directus.
  • "Invalid JSON": Ensure the "Data (JSON)" field contains properly formatted JSON.
  • "Field 'X' is required": Add all required fields for the collection in your data.
  • "Unauthorized" or "Forbidden": Verify your API credentials and permissions.

Links and References

Discussion