Environment Variables

Define and reuse common values across requests

Insomnia supports the ability to share common variables across requests and manage them in one place. The environment is defined as JSON, and you can put whatever you want in it.

Sample Environment:

	"base_url": "https://api.myproduct.com/v1",
	"api_key": "live_0a7b973038f4f6ee5",
	"user_id": "user_0138tsrat8902n4pt",
	"name": "gregory schier",
	"locales": {
		"english": "en-US",
		"french": "fr-FR"

Variable names must only contain letters, numbers, and underscores

You can reference the environment in any request by using the Nunjucks template syntax.

Sample URL:

{{ base_url }}/users/{{ user_id }}

Sample JSON Request body:

  "type": "User",
  "id": "{{ user_id }}",
  "name": "{{ name | title }}",
  "locale": "{{ locales.english }}"

Managing Environments

You can open the environment manager by clicking the environments dropdown in the top left. From there, you can edit the global environment, or create sub-environments.

Environment Dialog

Base Environment

Variables in the global environment can be used in any request at any time. It is also common to reference other environment variables from the base environment to cut down repetition. Here’s an example of building a base_url from scheme and host variables defined in the sub environment.

Base environment referencing other variables

Sub Environments

Variables in sub environments can be used when the desired sub environment is active. You can activate a sub environment by clicking it in the environment dropdown, located near the top of the sidebar.

Tip! Sub environments can be created as Private, meaning it will they will never be synced or exported.

Sub environments can also be assigned a specific color, to help identify which environment is active at a given time.

Insomnia Environment Dropdown

Environment Overrides

For more fine-grained control, you can override environment variables at the folder level. You can access theses overrides from the folder dropdown in the sidebar.

Recursive Environments

Environment variables can contain other environment variables. A common use case for this is building the base URL for a service:

  "base_url": "https://{{ host }}/api/{{ version }}"

Then, these can be overridden in a sub environment, as needed:

  "host": "production.api.com",
  "version": "1.3"

Want to talk more? Just reach out, I'd love to help!