Directus icon

Directus

Consume Directus API

Overview

The Directus - Preset: Update Multiple operation allows you to update multiple preset records in your Directus instance at once. This is particularly useful for batch-updating settings or configurations that are stored as presets, such as user interface layouts, filters, or other saved views. For example, if you need to change the layout property for several presets simultaneously, this operation streamlines the process by letting you specify all changes in a single request.

Practical scenarios:

  • Updating the layout of multiple admin dashboard presets.
  • Changing filter criteria for several saved views at once.
  • Bulk-modifying properties of presets after a schema or UI update.

Properties

Name Type Meaning
Data (JSON) json The JSON object containing the update instructions. It must include:
- keys: An array of primary keys identifying the presets to update.
- data: An object with the fields and values to update for those presets.

Example input:

{
  "keys": [15, 64],
  "data": {
    "layout": "tabular"
  }
}

Output

The node returns a json field containing the result of the update operation. The structure typically reflects the updated preset objects as returned by the Directus API.

Example output:

{
  "id": 15,
  "layout": "tabular",
  // ...other preset fields
}

or, if multiple presets are updated:

[
  {
    "id": 15,
    "layout": "tabular",
    // ...other preset fields
  },
  {
    "id": 64,
    "layout": "tabular",
    // ...other preset fields
  }
]

If an error occurs and "Continue On Fail" is enabled, the output will contain an error field with the error message.

Dependencies

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

Troubleshooting

Common issues:

  • Invalid Keys: If any of the provided keys do not correspond to existing presets, those updates may fail.
  • Malformed JSON: If the Data (JSON) property is not valid JSON, the node will throw a parsing error.
  • Insufficient Permissions: The API credentials used must have permission to update presets; otherwise, you'll receive an authorization error.

Error messages and resolutions:

  • "Cannot read property 'keys' of undefined": Ensure your input JSON includes both keys and data.
  • "Invalid JSON": Double-check your JSON syntax in the input.
  • "403 Forbidden" or "401 Unauthorized": Verify your Directus API credentials and permissions.

Links and References

Discussion