Directus icon

Directus

Consume Directus API

Overview

The Directus - Authentication: Refresh Token operation in n8n allows you to refresh a JWT access token using a valid, non-expired refresh token. This is particularly useful for maintaining authenticated sessions with the Directus API without requiring users to log in again when their access token expires.

Common scenarios:

  • Automated workflows that need to maintain long-lived sessions with Directus.
  • Scheduled jobs or integrations where re-authentication should be seamless and not require user intervention.
  • Any process where you want to avoid service interruptions due to expired tokens.

Practical example:
Suppose you have an n8n workflow that periodically syncs data from Directus. Instead of prompting for credentials every time the access token expires, you can use this node to refresh the token automatically and continue your operations uninterrupted.


Properties

Name Type Meaning
Refresh Token String The JWT refresh token you want to use for obtaining a new access token. Must not be expired.

Output

The output will be a JSON object containing the refreshed authentication data returned by the Directus API. Typically, this includes:

{
  "access_token": "string",
  "expires": number,
  "refresh_token": "string"
}
  • access_token: The new JWT access token.
  • expires: Expiry timestamp or duration for the new access token.
  • refresh_token: (May be present) A new refresh token if issued by the API.

If the request fails, and "Continue On Fail" is enabled, the output will contain an error message:

{
  "error": "Error message string"
}

Dependencies

  • Directus API: You must have a running Directus instance accessible from n8n.
  • API Credentials: The node requires valid Directus API credentials configured in n8n under the name directusApi.

Troubleshooting

Common issues:

  • Expired or Invalid Refresh Token: If the provided refresh token is expired or invalid, the API will reject the request.
    • Resolution: Ensure you are using a valid, unexpired refresh token.
  • Incorrect Credentials Configuration: If the Directus API credentials are not set up correctly in n8n, the request will fail.
    • Resolution: Double-check your credentials in n8n's credential manager.
  • Network/Connectivity Issues: If n8n cannot reach the Directus server, the request will fail.
    • Resolution: Verify network connectivity and Directus server availability.

Possible error messages:

  • "Invalid refresh token": The token is incorrect or has expired.
  • "Missing required parameter: refresh_token": The input property was not provided.
  • "401 Unauthorized": The credentials are not accepted by the Directus API.

Links and References

Discussion