Actions109
- Field Actions
- Item Actions
- Activity Actions
- Asset Actions
- Authentication Actions
- Collection Actions
- Extension Actions
- File Actions
- Folder Actions
- Permission Actions
- Preset Actions
- Relation Actions
- Revisions Actions
- Roles Actions
- Settings Actions
- Users Actions
- Utilities Actions
- Webhooks Actions
Overview
The Directus node for n8n, when configured with the resource Authentication and operation Login, allows you to authenticate a user against a Directus instance. This operation is used to obtain an access token (or set a session cookie) by providing user credentials (email and password), and optionally a one-time password (OTP) if two-factor authentication (2FA) is enabled.
Common scenarios:
- Automating login to Directus in workflows that require authenticated API calls.
- Retrieving access tokens for subsequent requests to protected endpoints.
- Handling 2FA-enabled logins by supplying OTP codes.
Practical examples:
- Logging in as an admin to perform administrative tasks via n8n.
- Authenticating users before performing data operations in Directus.
- Integrating Directus authentication into multi-step automation flows.
Properties
| Name | Type | Meaning |
|---|---|---|
| Password | string | Password of the user. Required unless using JSON/RAW Parameters. |
| string | Email address of the user you're retrieving the access token for. Required unless using JSON/RAW Parameters. | |
| JSON/RAW Parameters | boolean | If true, allows specifying the request body as raw JSON instead of individual fields. |
| Body Parameters | json | Body parameters as JSON or RAW. Used only if "JSON/RAW Parameters" is true. |
| Additional Fields | collection | Optional fields: - Mode: Choose between retrieving the token as a string ("json") or setting it as a cookie ("cookie"). - OTP: One-time password for 2FA-enabled accounts. |
Output
- The output is a single object in the
jsonfield containing the response from the Directus/auth/loginendpoint. - Typical structure includes:
- For successful login:
{ "access_token": "...", "expires": "...", "refresh_token": "...", "user": { ... } } - If "Mode" is set to "cookie", the session may be established via cookies (handled internally; output may differ).
- If an error occurs and "Continue On Fail" is enabled, the output will contain:
{ "error": "Error message" }
- For successful login:
Dependencies
- Directus API: Requires a running Directus instance accessible from n8n.
- API Credentials: You must configure the
directusApicredential in n8n with the appropriate base URL and (if needed) initial authentication details. - Network Access: n8n must be able to reach the Directus server.
Troubleshooting
Common issues:
- Invalid credentials: If the email or password is incorrect, the login will fail.
- 2FA required: If 2FA is enabled but no OTP is provided, login will fail.
- Incorrect JSON format: When using "JSON/RAW Parameters", ensure the JSON is valid.
- Mode mismatch: If "Mode" is set incorrectly, you may not receive the expected token or session.
Typical error messages:
"Invalid credentials": Check the email and password."OTP required"or"Invalid OTP": Provide a valid one-time password if 2FA is enabled."Unexpected token": Indicates malformed JSON in "Body Parameters".
How to resolve:
- Double-check all input values.
- If using JSON/RAW, validate your JSON syntax.
- Ensure the Directus instance is reachable and the API path is correct.
- If using 2FA, generate a fresh OTP code.