Directus icon

Directus

Consume Directus API

Overview

The node integrates with the Directus API to manage "Presets" resources, specifically supporting the "List" operation. It fetches a list of preset objects from a Directus instance, allowing users to retrieve all presets or limit the number returned. The node supports advanced query customization, including filtering, sorting, grouping, and aggregation.

This node is beneficial in scenarios where you want to automate workflows involving configuration presets stored in Directus, such as fetching presets for dynamic UI generation, reporting, or further processing in automation pipelines.

Example use cases:

  • Retrieve all presets to synchronize them with another system.
  • Fetch a limited number of presets with specific filters applied.
  • Export presets data as CSV, JSON, or XML files for reporting or archival.

Properties

Name Meaning
Return All Boolean flag to return all results or limit the number of returned presets.
Limit Number specifying the maximum number of presets to return when "Return All" is false. Range: 1 to 100.
Split Into Items Boolean indicating whether to output each element of the returned array as a separate item (true) or as a single array (false).
JSON/RAW Parameters Boolean to choose between setting query parameters via UI fields or providing raw JSON input.
Query Parameters JSON object representing query parameters as key-value pairs, used if "JSON/RAW Parameters" is true.
Additional Fields Collection of optional fields to customize the query, including:
- Aggregate Aggregation functions to perform calculations on preset fields, e.g., count, sum, average, min, max.
- Binary Property for Export Data String name of the binary property where exported file data will be saved. Default is "data".
- Deep (JSON) JSON object to specify nested relational dataset query parameters.
- Export Option to export the API response to a file format: CSV, JSON, or XML.
- Fields String to control which fields are returned in the response.
- File Name for Export Data String specifying the filename (without extension) for exported data. Default is "export".
- Filter (JSON) JSON object defining conditions to filter the collection items.
- Group By String specifying fields to group by for aggregation purposes, e.g., "author,year(publish_date)".
- Meta String specifying metadata to include in the response.
- Offset Number of items to skip when fetching data.
- Search String to filter items containing the search query in any field.
- Sort String defining sort order using CSV of fields; prefix with "-" for descending, "?" for random.

Output

The node outputs JSON data representing the fetched presets. Depending on the "Split Into Items" property, it either outputs an array of presets as a single item or each preset as a separate item.

If the "Export" option is selected, the node also outputs binary data containing the API response saved as a file in the chosen format (CSV, JSON, or XML). This binary data is accessible under the specified binary property name (default "data") and includes appropriate MIME type and filename.

Dependencies

  • Requires connection credentials to a Directus API instance, including an API authentication token.
  • Uses internal helper methods to make HTTP requests to the Directus API endpoints.
  • No additional external dependencies beyond the Directus API and n8n environment.

Troubleshooting

  • Common issues:

    • Invalid or missing API credentials will cause authentication failures.
    • Incorrect JSON syntax in "Query Parameters" or "Filter" fields may cause parsing errors.
    • Requesting more items than allowed by the API or exceeding limits may result in errors.
    • Selecting export formats without proper permissions or unsupported formats may fail.
  • Error messages:

    • Authentication errors typically indicate invalid API keys or tokens; verify credentials.
    • JSON parse errors suggest malformed JSON input; validate JSON syntax carefully.
    • API rate limiting or quota exceeded errors require checking Directus server limits.
    • Network or connectivity errors indicate issues reaching the Directus API endpoint.
  • Resolutions:

    • Ensure valid and active API credentials are configured in n8n.
    • Use JSON validators to check raw JSON inputs before saving.
    • Adjust "Limit" and "Return All" settings to comply with API constraints.
    • Confirm that the Directus instance is reachable and operational.

Links and References

Discussion