Parameterize Hoppscotch API Requests with Environment Variables
Use Hoppscotch environments to replace hardcoded URLs and tokens with {{variable}} placeholders before a request sends. Includes a staging configuration, limits, and verification steps.
01 Jul 2026, 06:06 UTC

Start with the useful answer
If you copy the same API request for staging, production, and local development, you risk sending a production token to a staging server or leaving a hardcoded localhost URL in a shared collection. Hoppscotch resolves double-brace references such as {{base_url}} in request URLs, headers, query parameters, and body content immediately before sending. Define those names in an environment, activate that environment, and every open request that references them uses the active values.
How substitution works
Hoppscotch stores variables inside environments. When you activate an environment, the client substitutes its values into all open requests that reference matching names. Substitution happens right before the request is sent, not when you save the request. Variable names are case-sensitive, so {{base_url}} and {{Base_URL}} are different variables. If you reference a name that does not exist in the active environment, Hoppscotch can leave the literal text {{name}} in the outgoing request, which commonly produces 404 or 401 errors.
Worked configuration: a staging environment
This example uses placeholder values. Replace api.staging.example.com and abc123 with values for your own systems, and treat tokens as secrets.
- Open the Environments panel in Hoppscotch and create a new environment named
staging. - Add two variables:
base_url:api.staging.example.comtoken:abc123- Activate the
stagingenvironment. - Create a GET request with this URL:
{{base_url}}/v1/users
Add a header:
Authorization: Bearer {{token}}
With staging active, Hoppscotch sends the request to https://api.staging.example.com/v1/users with the header Authorization: Bearer abc123. If you then activate a production environment that defines the same variable names with different values, the same request preview updates to the production URL and token without editing the request itself.
What to check after switching environments
- Open the request preview or send the request and confirm the URL contains the active environment's
base_url, not the literal text{{base_url}}. - Confirm the
Authorizationheader contains the active token value. - Switch to another environment and verify the preview changes to match that environment's values.
Limits and common mistakes
- Undefined variables leave literals. Referencing {{api_key}} in a request while the active environment has no
api_keycan send the literal string{{api_key}}to the server, causing authentication or routing failures. - Case sensitivity. {{token}} and {{Token}} are treated as separate variables. A typo in the variable name will not substitute.
- Exports may contain plaintext secrets. Exported environment and collection JSON can store API keys and tokens in plain text. Handle those files as secrets and avoid committing them to version control.
- Postman imports are partial. Hoppscotch supports importing Postman Collection v2.1 JSON, including collection and environment variables. Postman-specific features such as pre-request scripts and test snippets may not import or execute.
- No automatic dynamic values. Hoppscotch does not automatically generate timestamps or random IDs unless the version in use explicitly provides a built-in dynamic variable.
Verify the result
- Create an environment with at least one variable and reference it in a request URL or header.
- Switch to a different environment and confirm the request preview updates to the new value.
- Send the request to an endpoint you control or a public echo service and inspect the received query string or header to confirm it contains the substituted value rather than the literal template.
- Export the environment or collection as JSON and inspect the variable array to confirm the names and initial values match what you entered in the UI.
Do not rely on the visual preview alone for authorization headers; send a real request to an endpoint you can inspect, because the preview may display a substituted value while the actual request behaves differently if another variable scope or override is involved.
Undoing an environment change
Activating an environment changes the active client state. To revert, switch back to the previous environment or deactivate the current one. Requests that referenced variables from the old environment will resume using the newly active environment's values, or leave undefined references as literal templates.