Directus icon

Directus

Consume Directus API

Overview

The Directus n8n node, when configured with the Item resource and the Get operation, retrieves a single item from a specified collection in a Directus instance by its unique ID. This is useful for workflows where you need to fetch detailed information about a specific record (item) stored in your Directus-managed database.

Common scenarios:

  • Fetching user profile data by user ID.
  • Retrieving a product's details for order processing.
  • Looking up a file or article by its unique identifier for further automation steps.

Practical example:
Suppose you have a workflow that processes support tickets. You can use this node to fetch all details of a ticket (item) by its ID from the "tickets" collection, then pass those details to another system or send a notification.


Properties

Name Type Meaning
ID String Unique ID of the item to retrieve from the specified collection. Required.
Collection Options The name of the parent collection containing the item. Required.
Return All Boolean If enabled, returns all results (not relevant for single item get, but present due to shared interface).
Limit Number Maximum number of objects to return if "Return All" is false (not relevant for single item get).
Additional Fields Collection Optional advanced query parameters. See below for sub-options.

Additional Fields (sub-options):

  • Aggregate: Allows specifying aggregation functions (e.g., count, sum) on fields. Not typically used for single item retrieval.
  • Binary Property for Export Data: Name of the binary property to store exported file data.
  • Deep (JSON): Set nested relational query parameters as JSON.
  • Export: Choose to export the API response as a file (json, csv, xml).
  • Fields: Specify which fields to include in the returned object.
  • File Name for Export Data: File name (without extension) for exported data.
  • Filter (JSON): Filter conditions as JSON (not typical for single item get).
  • Group By: Grouping for aggregations (not typical for single item get).
  • Meta: Specify what metadata to return.
  • Offset: How many items to skip (not typical for single item get).
  • Search: Search query string (not typical for single item get).
  • Sort: Sorting options (not typical for single item get).

Output

  • The output will be a single object in the json field representing the requested item from the specified collection.
  • If the Export option is used, the node can also output binary data (e.g., CSV, JSON, XML file) under the specified binary property name.

Example output (json):

{
  "id": "15",
  "title": "Sample Article",
  "author": "John Doe",
  "created_at": "2024-06-01T12:00:00Z",
  ...
}

The actual structure depends on the fields defined in your Directus collection and any field selection applied.

If exporting, the output will also include a binary property with the exported file.


Dependencies

  • Directus API: Requires access to a running Directus instance.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.

Troubleshooting

Common issues:

  • Invalid ID or Collection: If the provided ID or collection does not exist, the node will throw an error or return an empty result.
  • Permissions: Insufficient permissions for the API user may result in authorization errors.
  • Malformed JSON in Advanced Fields: If using JSON fields like "Deep" or "Filter", ensure valid JSON syntax to avoid parsing errors.

Error messages and resolutions:

  • "Cannot find item": Check that the ID and collection are correct and exist in Directus.
  • "Unauthorized": Verify your API credentials and user permissions.
  • "Unexpected token ... in JSON": Ensure any JSON input is properly formatted.

Links and References


Discussion