Variables

Manage typed global variables accessible from any workflow stage - like programming language variables

Overview

This node manages global workflow variables that can be accessed and modified at any stage of an n8n workflow. It allows you to initialize, set, get, view, and clear typed variables similar to how variables work in programming languages. This is useful for storing state, counters, configuration values, or complex data objects that need to persist and be shared across multiple nodes within the same workflow execution.

Common scenarios include:

  • Storing API tokens or URLs once and reusing them throughout the workflow.
  • Keeping track of counters or flags to control workflow logic.
  • Saving JSON objects or arrays as intermediate data.
  • Managing dates or timestamps relevant to the workflow process.

Example: Initialize a variable pageNumber with a number value 1, then increment it after each HTTP request to paginate through API results.

Properties

Name Meaning
Operation The action to perform on variables: "Clear All Variables", "Get Variable", "Initialize Variables", "Set Variable", or "View All Variables".
Variable Name The name of the variable to set or get (e.g., URL, pageNumber, maxRetries). Required for "set" and "get" operations.
Variable Type The type of the variable value when setting it. Options: Boolean, Date, JSON, Number, String. Only shown for "set" operation.
Variable Value The value to store in the variable. Supports expressions. Type depends on the selected Variable Type: text, number, boolean, JSON object/array, or date/time. Only shown for "set" operation.
Initial Variables A collection of variables to initialize at once, each with a name, type, and initial value. Used only in the "initialize" operation.

Output

The node outputs an array of items where each item contains a json property with the following structure depending on the operation:

  • Initialize: Outputs all initialized variables merged into the input JSON.
  • Set Variable: Outputs all current variables merged into the input JSON after setting the specified variable.
  • Get Variable: Outputs the input JSON extended with:
    • operation: "get"
    • variableName: the requested variable's name
    • variableValue: the value of the variable (or undefined if not found)
    • A property named after the variable containing its value
    • status: "found" or "not_found"
    • message: descriptive text about retrieval success or failure
  • View All Variables: Outputs all current variables merged into the input JSON.
  • Clear All Variables: Outputs the input JSON extended with:
    • operation: "clear"
    • clearedVariables: list of cleared variable names
    • clearedCount: number of cleared variables
    • message: summary message about clearing

No binary data output is produced by this node.

Dependencies

  • No external services or APIs are required.
  • Uses n8n's internal static workflow data storage to persist variables globally during workflow execution.
  • Requires no special credentials or environment variables.

Troubleshooting

  • Missing Variable Name: If you try to set or get a variable without specifying its name, the node throws an error "Variable name is required".
  • Invalid Number Value: Setting a variable of type number with a non-numeric value causes an error "Invalid number value".
  • Invalid Date Value: Providing an invalid date string results in "Invalid date value".
  • Invalid JSON Value: Supplying malformed JSON triggers "Invalid JSON value".
  • Variable Not Found: Getting a variable that does not exist returns a status "not_found" with a corresponding message but does not throw an error.
  • To avoid workflow interruption on errors, enable "Continue On Fail" in the node settings.

Links and References

Discussion