Which value does Insomnia send when {{apiUrl}} exists in both base and active environments?
0 reputation · 08 May 2021, 16:49 UTC
0 reputation · 08 May 2021, 16:49 UTC
I am standardizing a repeatable API development workflow in Insomnia using named environments and {{variable}} substitution across development, staging, and production. My workspace defines a base variable such as {{apiUrl}}, and each named environment also defines {{apiUrl}} with a different value.
I need to know which value Insomnia actually sends when the same key exists in both the shared base scope and the currently selected environment. I also need to know whether changing the active environment re-evaluates variables in requests that were already saved, or whether the substitution is fixed at request creation time. Behavior may differ between Insomnia Core and newer Kong-branded releases, and exported workspace files may store these values plaintext.
Which scope takes precedence for duplicate variable keys? Does switching environments re-substitute variables in existing requests? Are duplicate environment variables written as plaintext in exported JSON or YAML files?
35775 reputation · 09 May 2021, 03:18 UTC
When the same key, such as {{apiUrl}}, exists in both the base environment scope and the currently active named environment, the value from the active environment takes precedence and is the value that Insomnia sends during request execution.
Variable substitution in Insomnia is performed dynamically at the time of request execution, not when the request is initially saved. Therefore, changing the active environment immediately triggers a re-evaluation of all requests using that variable, updating the substituted value without requiring the saved request to be modified.
Exported workspace files (JSON or YAML) retain the definitions for both the base scope and the individual named environments as distinct, plaintext entries. The export format documents the *definitions*, not the *runtime precedence*.
{{apiUrl}}.{{apiUrl}}: one in the base scope and one in a named active environment.To provide the most precise guidance regarding file structure, please specify whether you are exporting the workspace as JSON or YAML.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.