How to set an environment variable in the previous request and then pass it into the following request?
See original GitHub issue- Newman Version (can be found via
newman -v
): 3.6.0 - OS details (type, version, and architecture): windows7
- Are you using Newman as a library, or via the CLI? via CLI
- Did you encounter this recently, or has this bug always been there: just started to use newman recently
- Expected behaviour: I am expecting the environment variable get set during request1 then from request2, I can pass in the value into the header
- Command / script used to run Newman: newman run collection.json -e env.json
- Sample collection, and auxilliary files (minus the sensitive details): I am running the following collection from command line and having an env json exported with base_url and cookie, the cookie value is set during the first request run. Can I do the following to get the environment variable set and pass along?
{
"variables": [],
"info": {
"name": "Sophie",
"_postman_id": "1eb379e2-2e4e-6c43-c72e-1127cd3e1f0b",
"description": "Sophie's Test",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "get",
"description": "",
"item": [
{
"name": "login",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests[\"Status code is 200\"] = responseCode.code === 200;",
"postman.setEnvironmentVariable(\"cookie\", \"loginSession=\"+postman.getResponseCookie(\"loginSession\").value);",
""
]
}
}
],
"request": {
"url": "http://{{base_url}}/sophie_ui/",
"method": "GET",
"header": [
{
"key": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"description": ""
}
],
"body": {},
"description": ""
},
"response": []
},
{
"name": "login with username/pwd",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests[\"Status code is 200\"] = responseCode.code === 200;"
]
}
}
],
"request": {
"url": "http://{{base_url}}/login/security_check",
"method": "POST",
"header": [
{
"key": "Cookie",
"value": "{{**cookie**}}",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "j_username=&j_password="
},
"description": ""
},
"response": []
}
]
}
]
}
- Screenshots (if applicable):
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
How to update environment variables based on a ... - YouTube
Sometimes, the response from a request is required first in order to continue with all the other API requests currently stored in your ......
Read more >How To Set Environment Variables - Twilio
In the new window that opens, click on the Advanced tab and afterwards on the Environment Variables button in the bottom right of...
Read more >Extracting Data from Responses and Chaining Requests
For this example, we'll create and set a blank test environment. ... Let's add a form-data variable to the '/status' request.
Read more >Environment variables set by HTTP Server - IBM
Variable Name Type Description
QZHBIS_CLUSTER_ENABLED Non‑SSL
REDIRECT_QUERY_URL Non‑SSL
HTTPS_SESSION_ID SSL Set to NULL by default when used with HTTP Ser...
Read more >Use environment variables | Cloud Run Documentation
When you set environment variables, they are injected into the container and are accessible to your code. Environment variables are set as key/value...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
And also, same question as I asked on the closed thread earlier yesterday. Since the value of that environmental parameter is change dynamically, is it possible that the following test case is not getting the updated value?
Hey guys , I went through the issue and didn’t get a proper solution , however this ticket had been closed. this is my Newman response : in first request it gets the stock id and creates an order for that, when it gets the order, request still using the old value of orderId, while it has to use “01646” . how can I pass this value to my global environment ? instead of using old value? the third test is failing as for it can’t find old order id!
this is my newman run command:
newman run IntegrationTests.postman_collection.json -e IntegrationTests_DEV.postman_environment.json -g IntegrationTests_Dev.postman_globals.json --export-environment IntegrationTests_DEV.postman_environment.json export-global IntegrationTests_Dev.postman_globals.json