Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Authentication → Login

AI-generated

Overview

The Directus (DrWade) n8n node for the resource Authentication and operation Login allows you to authenticate a user against a Directus instance. This operation is used to log in with an email and password, optionally including two-factor authentication (2FA) via OTP, and retrieve an access token or set a session cookie.

Common scenarios:

  • Automating login to Directus for subsequent API calls.
  • Integrating Directus authentication into workflows that require dynamic user sessions.
  • Handling 2FA-enabled logins programmatically.

Practical examples:

  • Logging in as an admin to perform administrative tasks in a workflow.
  • Authenticating end-users before allowing them to interact with protected resources in Directus.
  • Automating periodic data syncs that require authenticated access.

Properties

Name Type Meaning
Password string Password of the user. Required unless using JSON/RAW Parameters.
Email 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; disables standard input fields.
Body Parameters json Used when "JSON/RAW Parameters" is true. The full request body as JSON or RAW.
Additional Fields collection Optional. Allows setting extra parameters:
- Mode: Choose between receiving the token as a string ("JSON") or as a cookie ("Cookie").
- OTP: One-time password for 2FA if enabled.

Output

  • The output will be a single object in the json field containing the response from the Directus /auth/login endpoint.
  • 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 by n8n), and the response may differ.
    • If there is an error (and "Continue On Fail" is enabled), the output will contain:
      {
        "error": "Error message"
      }
      

Dependencies

  • Directus API: You must have access to a running Directus instance.
  • API Credentials: The node requires configured credentials (directusApi) in n8n.
  • User Account: The email/password provided must correspond to a valid Directus user.
  • 2FA: If the account has 2FA enabled, a valid OTP must be supplied.

Troubleshooting

Common issues:

  • Invalid credentials: If the email or password is incorrect, the login will fail.
  • Missing required fields: Not providing required fields (email, password) when not using JSON/RAW mode will result in errors.
  • 2FA required: If 2FA is enabled but no OTP is provided, login will fail.
  • Malformed JSON: When using JSON/RAW Parameters, ensure the JSON is correctly formatted.

Common error messages:

  • "Invalid credentials": Check the email and password.
  • "OTP required" or "Invalid OTP": Provide a valid one-time password if 2FA is enabled.
  • "Malformed request body": Ensure your JSON in "Body Parameters" is valid.

Links and References

Discussion