Directus (DrWade) icon

Directus (DrWade)

Consume Directus API

Utilities → Get a Random String

AI-generated

Overview

The "Get a Random String" operation under the Utilities resource in this custom n8n node allows users to generate a random string of a specified length. This is useful in scenarios where you need unique identifiers, temporary passwords, tokens, or any other use case that requires a random alphanumeric string.

Practical examples:

  • Generating a random password for a new user.
  • Creating a unique token for API requests.
  • Producing random codes for testing or data anonymization.

Properties

Name Type Meaning
Additional Fields Object A collection of optional parameters.
Length Number (Within "Additional Fields") Specifies the desired length of the random string. If not set, a default may be used by the backend.

Output

The output will be an object with a json field containing the result. The structure is as follows:

{
  "result": "<random_string>"
}
  • result: The generated random string of the requested length.

If the response from the API is not an object (e.g., a plain string), it will still be wrapped in a result property for consistency.

Dependencies

  • Directus API: Requires access to a Directus instance with the appropriate endpoint enabled.
  • API Credentials: The node expects valid Directus API credentials configured in n8n under the name directusApi.

Troubleshooting

Common issues:

  • Missing or invalid credentials: If the Directus API credentials are not set up correctly, the node will fail to connect.
  • Length parameter issues: Providing a non-numeric or out-of-range value for "Length" may cause errors or unexpected results.
  • API errors: If the Directus backend does not support the /utils/random/string endpoint, or if there are permission issues, the node will return an error message.

Error messages and resolutions:

  • "Cannot read property 'length' of undefined": Ensure that "Additional Fields" is provided and contains a valid "Length" value.
  • "401 Unauthorized" or similar: Check your API credentials.
  • "Endpoint not found": Verify that your Directus instance supports the utilities endpoints.

Links and References

Discussion