Last active
April 16, 2020 05:21
-
-
Save imsmo/a26d05180edd2b06facf64ecf0c3bf19 to your computer and use it in GitHub Desktop.
Postman Useful Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-----------How to set value as a global and local variable from login response start------- | |
Step1: add this code in "Tests" | |
pm.test("GetAuthkey", function () { | |
var jsonData = pm.response.json(); | |
pm.globals.set("globalAuthKey", jsonData.data.auth_key); | |
pm.environment.set("EnvironmentAuthKey", jsonData.data.auth_key); | |
}); | |
Note: GetAuthkey: any name you can set, | |
globalAuthKey: Global variable name as per your choice. For get (pm.globals.set) | |
EnvironmentAuthKey: Environment variable name as per your choice. For set(pm.environment.set) | |
jsonData.data.auth_key: Key path from response | |
Step2: Then use in afterauth api this variable using {{EnvironmentAuthKey}} or {{globalAuthKey}} | |
//-----------How to set value as a global and local variable from login response end------- | |
//-----------How to unset value as a global and local variable from login response start------- | |
pm.globals.unset("AuthKey"); | |
pm.environment.unset("AuthKey"); | |
//-----------How to unset value as a global and local variable from login response end------- | |
//-----------How to get value as a global and local variable from login response start------- | |
pm.globals.get("AuthKey"); | |
pm.environment.get("AuthKey"); | |
//-----------How to get value as a global and local variable from login response end------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment