mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[GH-ISSUE #1468] Dynamic environment variables #473
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#473
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 @pikausp on GitHub (Feb 5, 2021).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/1468
Hello,
is it possible to dynamically set environment variables e.g. within tests, similar to Postman? Our use-case is to automatically set authentication token after calling sign-in/refresh endpoints and not having to manually copy and set the token.
Thank you for any tips
@liyasthomas commented on GitHub (Feb 5, 2021):
Possibly a duplicate of #1425 and #984
As of now, environment variables can't be changed from Tests script.
Refer: https://github.com/hoppscotch/hoppscotch/issues/1425#issuecomment-758806073
@tudordre commented on GitHub (May 11, 2023):
@liyasthomas was this developed? Wasn't able to find more info than here and this issue https://github.com/hoppscotch/hoppscotch/issues/984
@liyasthomas commented on GitHub (May 12, 2023):
Hi @tudordre, refer to our documentation to learn how to create environment variables from pre request scripts and tests: https://docs.hoppscotch.io/documentation/getting-started/rest/pre-request-scripts#setting-environment-variables#setting-environment-variables
@Muhammad-Mostafa commented on GitHub (Jul 31, 2023):
Hi @liyasthomas
Are there any updates about whether you guys added this feature of the ability to store the auth token in the environment variables. Can i write a script to store the auth token from login response to the environment variables?
I checked out your documentation, but didn't find a related something about this. thanks in advance.
@liyasthomas commented on GitHub (Jul 31, 2023):
Hi @Muhammad-Mostafa, you can now create, update environment variables directly from Test scripts.
Documentation: https://docs.hoppscotch.io/documentation/getting-started/rest/pre-request-scripts#setting-environment-variables%23setting-environment-variables
@umardev500 commented on GitHub (Nov 16, 2023):
how to set automatically after login
@liyasthomas commented on GitHub (Nov 16, 2023):
Setting Environment Variables from API Responses
@Moni142002 commented on GitHub (Sep 18, 2024):
Hii
Is it possible to dynamically add a token to set an environment variable in Hoppscotch
var response = pw.response.json();
pw.env.set("token", "response.token");
I'm trying this one in a Pre-request Script but its not working as I expected
Pls suggest me some ideas....
@liyasthomas commented on GitHub (Sep 18, 2024):
Can you remove the quotes ("") around
response.tokenand try again?Can you refer to this documentation for more info: https://docs.hoppscotch.io/documentation/features/scripts#setting-environment-variables-from-api-responses
@Moni142002 commented on GitHub (Sep 18, 2024):
@liyasthomas Tried but not working..
I've reviewed the documentation, but it only shows how to add a random value to the URL. However, I want to dynamically extract a value from the request body and set it as an environment variable
@liyasthomas commented on GitHub (Sep 18, 2024):
Pre-request scripts run before executing the request.
Post-request tests run after executing the request.
If you want to access the response body from scripts, you need to add them to the Test scripts of the request so that it'll have access to the response context.
Can you add the scripts to tests and see if it works?
@Moni142002 commented on GitHub (Sep 18, 2024):
@liyasthomas But its not working...I want to know..Is it possible to add token value dynamically to set environment variable when i sign In or sign up in Hoppscotch..
@liyasthomas commented on GitHub (Sep 18, 2024):
I'm afraid that's not possible in Hoppscotch at the moment. But I'm curious, what is the use-case you're trying to achieve?
@Moni142002 commented on GitHub (Sep 18, 2024):
const jsonData = pw.response.body;
pw.env.set("token", jsonData.token);
This script is working using the jsonData variable
Thanks @liyasthomas..