Directus icon

Directus

Consume Directus API

Overview

The Utilities → Sort Items operation in this n8n node allows you to reorder items within a specified collection in Directus. By specifying the primary key of the item to move and the target position, you can programmatically change the order of items. This is particularly useful for managing ordered lists, such as menus, categories, or any custom-sorted data in your Directus collections.

Practical examples:

  • Moving a menu item to a new position in a navigation list.
  • Reordering featured products on an e-commerce homepage.
  • Adjusting the sequence of steps in a workflow stored in Directus.

Properties

Name Type Meaning
To Number Primary key of the item where you want to move the current item to (target position).
Item Number Primary key of the item you want to move (the item being reordered).
Collection Options Identifier of the collection containing the items to be sorted.

Output

  • The output will be a single object in the json field, typically reflecting the result of the sort operation from Directus.
  • If the API returns a simple value (string, number, boolean), it will be wrapped in a { "result": ... } object.
  • Example output:
    {
      "result": true
    }
    
    or, if the API returns more details:
    {
      "status": "success",
      "message": "Item moved"
    }
    

Dependencies

  • Directus API: Requires access to a Directus instance with appropriate permissions to modify the specified collection.
  • API Credentials: You must configure the directusApi credentials in n8n for authentication.

Troubleshooting

  • Common Issues:

    • Invalid Collection: If the collection identifier is incorrect, the operation will fail.
    • Nonexistent Item/To IDs: If either the item to move or the target position does not exist, an error will occur.
    • Insufficient Permissions: The API user must have permission to update the collection's order.
  • Error Messages & Resolutions:

    • "Collection not found": Check that the collection name is correct and exists in Directus.
    • "Item not found": Ensure both the 'Item' and 'To' IDs are valid primary keys in the collection.
    • "Permission denied": Verify that your API credentials have write access to the collection.

Links and References

Discussion