Directus icon

Directus

Consume Directus API

Overview

The "Items - Get" operation in this node allows you to retrieve data objects (items) from a specified collection within the Directus API. This operation is useful when you want to fetch specific records or lists of records from your Directus-managed database collections.

Common scenarios include:

  • Fetching a single item by its unique ID for detailed processing or display.
  • Listing multiple items with optional filtering, sorting, and pagination.
  • Exporting retrieved data into various formats such as JSON, CSV, or XML for reporting or integration purposes.
  • Applying aggregation functions like count, sum, average, min, max on fields within the collection.
  • Grouping results based on shared field values.

Practical examples:

  • Retrieve a blog post item by its ID from the "articles" collection.
  • List all users who signed up after a certain date, sorted by their signup date.
  • Export product inventory data as a CSV file for analysis.
  • Calculate the total sales amount per month by grouping sales items.

Properties

Name Meaning
ID Unique identifier of the item to retrieve. Required for fetching a single item.
Collection The name of the parent collection from which to get the item(s).
Return All Boolean flag indicating whether to return all matching results or limit the number of returned items.
Limit Maximum number of items to return if "Return All" is false. Value range: 1 to 100.
Additional Fields A collection of optional parameters to customize the query:
  Aggregate Aggregation functions to perform calculations on fields, such as Count, Count Distinct, Sum, Average, Minimum, Maximum, etc.
  Binary Property for Export Data Name of the binary property where exported data will be saved if export is enabled. Defaults to "data".
  Deep (JSON) JSON object allowing nested relational dataset queries by setting additional query parameters on related data.
  Export Format to save the API response as a file. Options: JSON, CSV, XML.
  Fields Comma-separated string specifying which fields to return in the response.
  File Name for Export Data File name (without extension) for the exported data file. Defaults to "export".
  Filter (JSON) JSON object defining conditions to filter items in the collection.
  Group By Field(s) to group results by, enabling aggregation functions to run on grouped data. Example: "author,year(publish_date)".
  Meta Specifies what metadata to include in the response.
  Offset Number of items to skip before starting to fetch data (for pagination).
  Search Text query to filter items containing the given search string in any of their fields.
  Sort Comma-separated list of fields to sort by. Prefix a field with "-" for descending order. Use "?" for random sorting.

Output

The output is an array of JSON objects representing the retrieved item(s) from the specified collection.

  • For a single item retrieval (get operation), the output contains one JSON object with the item's fields and values.
  • For listing multiple items (list operation), the output contains multiple JSON objects, each representing an item.
  • If export is enabled, the node also outputs the data as a binary file in the chosen format (JSON, CSV, or XML) under the specified binary property name.
  • Aggregation and grouping results are included in the JSON output according to the requested functions.
  • Pagination and filtering affect the subset of items returned.

Dependencies

  • Requires a valid connection to the Directus API via an API key credential configured in n8n.
  • The node uses Directus REST endpoints to perform operations on collections and items.
  • No additional external dependencies beyond the Directus API and n8n environment.

Troubleshooting

  • Invalid Collection Name: If the specified collection does not exist or is misspelled, the API will return an error. Verify the collection name matches exactly.
  • Missing or Invalid ID: For the get operation, the ID parameter is required. Omitting it or providing an invalid ID will cause errors.
  • API Authentication Errors: Ensure the API key credential is correctly set up and has sufficient permissions to access the requested collection and items.
  • Malformed JSON in Filters or Deep Parameters: When using JSON input for filters or deep relational queries, ensure the JSON syntax is correct to avoid parsing errors.
  • Limit Exceeded: The limit property must be between 1 and 100. Setting values outside this range may cause errors.
  • Export Issues: If exporting data, ensure the binary property name and file name are valid strings. Also, verify that the chosen export format is supported.
  • Network or API Downtime: Connectivity issues or Directus server downtime will result in request failures.

To resolve errors, check the error message returned by the node, validate input parameters, and confirm API credentials and permissions.

Links and References

Discussion