Variables
The Variables block allows you to create variables whose values can be updated at any point in an API. The Variables block is useful for updating a value over time in a Loop or Condition block, or for referencing a frequently used value across an API.

Access the variable value using .value
property on the variable name (e.g., myVar.value
).
Variable scoping
Variables follow lexical scoping like variables in code. As such, a variable is available to other API blocks at the same nesting level (or below), relative to where the Variables block is defined.


Updating / setting variable values
Variables are not typed so they can be updated to any value. In the example below, a variable called nextPage
is initialized to true
at the start of a backend API that is used to iterate through a paginated REST API. When a condition is met inside a While Loop further down in the API, the variable is updated to false
. This can be done with either another Variables block
or by setting the variable in code.
- Update Variable(s) with a Variables Block
- Update Variable(s) with code
Define a new Variables block in the same scope as the original Variables block, using the same variable name whose value you want to update.

Use the .set()
function call to update a variable’s value in a code block (e.g., myVar.set(“my new value”)
)

You cannot initialize a variable in code. Setting the initial value requires a Variables block.