Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Overview

The Directus (DrWade) n8n node for the resource Items and operation Create allows you to create a new item (record) in a specified Directus collection. This is useful when you want to automate the process of adding data to your Directus-managed database from within an n8n workflow.

Common scenarios:

  • Automatically adding new articles, products, users, or any custom content type to your Directus project.
  • Integrating external data sources with Directus by creating items based on incoming data.
  • Building workflows that enrich or transform data before inserting it into Directus.

Practical example:
Suppose you have a form submission on your website and want to store each submission as a new record in your "articles" collection in Directus. You can use this node to map the form fields to the required structure and create the item automatically.


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. This should contain the fields and values for the new item.

Output

  • The output will be a single json object representing the newly created item in the specified collection.
  • The structure of the output matches the Directus item object, which typically includes all fields of the created item, such as its ID and any default or auto-generated fields.

Example output:

{
  "id": 123,
  "title": "Hello world!",
  "body": "This is our first article",
  // ...other fields as defined in your collection
}
  • If an error occurs and "Continue On Fail" is enabled, the output will be:
{
  "error": "Error message"
}

Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n, which typically include the API URL and an access token or login details.

Troubleshooting

Common issues:

  • Invalid Collection Name: If the collection does not exist or is misspelled, the node will return an error.
  • Malformed JSON in Data: If the "Data (JSON)" property is not valid JSON or does not match the expected schema, the request will fail.
  • Missing Required Fields: If required fields for the collection are missing in the data, Directus will reject the creation.
  • Authentication Errors: Invalid or expired API credentials will result in authentication errors.

Common error messages:

  • "Collection not found": Check the collection name.
  • "Invalid payload" or "Malformed JSON": Ensure the Data (JSON) is correctly formatted.
  • "Unauthorized": Verify your API credentials.

Links and References


Discussion