Dynamic variables

Uses: Insomnia

You can use variables in Insomnia to specify values in your requests, such as URLs, query parameters, headers, request bodies, authentication configuration, or scripts. Besides environments, there are two other ways to define variables in Insomnia:

  • Iteration variables, which are used in the Collection Runner to change a variable value on each iteration
  • Local variables, which are temporary variables defined in a pre-request or after-response script for each request

Iteration data

When you open the Collection Runner on your collection, you’ll see an Upload Data button. This allows you to upload a file containing variable values for each iteration. You can upload either a SCV or JSON file.

Here’s an example of the expected structure:

Once you’ve uploaded this file, you can use these variables anywhere in your request:

  • In the URL, query parameters, body, or authentication with this format: {{variable_1}}
  • In scripts using iterationData: insomnia.iterationData.get('variable_1')

Local variables

In pre-request and after-response scripts, you can manipulate environments to set, modify, or unset variables, but you can also set local temporary variables using localVars. For example:

insomnia.variables.localVars.set("variable_name", "variable value")

You can then reference these temporary variables anywhere in your request:

  • In the URL, query parameters, body, or authentication with this format: {{variable_name}}
  • In scripts using insomnia.variables.localVars.get("variable_name")
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!