mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[GH-ISSUE #1425] Environment vars not working #459
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#459
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cddm13 on GitHub (Jan 12, 2021).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/1425
Describe the bug
Fails to set a value to env var when using an endpoint.
To Reproduce
Steps to reproduce the behavior:
pw.env.set("bearerToken", "aNewToken");I've also tried withpw.environment.set("bearerToken", "aNewToken")and the same for the pre-request scrip, however when I check the env var bearerToken it still contains the "initial" value.Expected behavior
When the request is completed the bearerToken environment variable value should be changed.
Screenshots

Desktop (please complete the following information):
Additional context
am I doing anything wrong? how can I accomplish this?
@liyasthomas commented on GitHub (Jan 12, 2021):
You cannot set an environment variable from
Testsscript - this feature is not available. Tests are for verifying your API responses only - read how.To add environment variables you can either write a
Pre-request scriptor use "Environments" tab in the sidebar.Add environment variable using pre-request script:
Use
pw.env.set("env_variable","env_value")Example:
Once an environment variable is set, you need to switch environments from "Environments" tab to change it's value. For making use of multiple environments - you can create an environment with name "Globals" whose variables are accessible on every environments.
This is not the expected behavior.
Let me know if you've any doubts.
@cddm13 commented on GitHub (Jan 12, 2021):
I did what you said but the env variable is not changing its value, here's my pre-request code:
pw.env.set('bearerToken', 'newToken');and here is my environment/ variable configuration:

as you can see the value of bearerToken is not changing to "newToken"
also, how can I set my environment variable "bearerToken" to = a property of the response (data.token) after this request is completed? because what I want is perform login and then assign that token value into my "barierToken" env that is used in another endpoint on which I need to be authenticated
@liyasthomas commented on GitHub (Jan 12, 2021):
Since this involves making two requests, adding token from first response to environment should be a manual process. Also you can make use of Authentication section to mention Bearer token after fetching the token first.
As of now, environment variables can't be changed from Tests script.
@skelet00r commented on GitHub (Jun 29, 2021):
@liyasthomas This is a very useful feature when sharing collections to setup flows that other users can easily run through steps. Without manually having to set all the little bits up.
I get that the tests tab is for asserting tests but one of the main use cases ive seen this is for exactly what the OP is asking for.
Its very much a blocker for me as an example wanting to migrate away from postman.
This doesn't stop at just bearer tokens for example, think getting a USERID from a login the subsequent request may require.
Is the status of this ticket WONTFIX or up for debate? If the feature is a PR away then happy to have a go at it.
@liyasthomas commented on GitHub (Jun 29, 2021):
This is one of our planned features. The already existing Hoppscotch APIs comes little short for all this features and some security concerns. We're working on an isolated JavaScript compiler along with a set of revamped Hoppscotch APIs that allows users to add/edit/delete environment variables from both pre-request and post-request scripts.
This first iteration of the MVP is expected to arrive in a week or so. Thank you for the patience, feel free to jump into our communication channels to connect with the core team. Feedbacks are welcome.
@kahennig commented on GitHub (Dec 15, 2021):
Hi liyasthomas,
this would be a great feature to have, I was wondering if the setting of env vars from the post-request scripts is nearing arrival?
Thanks,
Andi
@sergeidyga commented on GitHub (Jan 11, 2022):
+1. Hi! I also find this feature to be widely used. And it looks like a blocker for our team to migrate from Postman to Hoppscotch.
@xairoo commented on GitHub (Jan 23, 2022):
100% agree. Makes things so easy.
Also missing
console.logoutput for some debugging when writing tests or pre-request scripts.@ramunozp commented on GitHub (Apr 8, 2025):
It's 2025 and it still doesn't work...