vvdkuij
(vvdkuij)
June 18, 2022, 12:38pm
1
Postman version 9.21.2
Use a Mock service.
GET request
Situation:
The incoming request has a field: QR
I store the value of QR via an environment variable (variable_QR) in this way:
let param = pm.request.url.query.toObject().QR;
pm.environment.set (âvariable_QRâ,param);
This goes well and is kept as Current value.
Then I fill the response with this variable (variable_QR)
âqrâ: {{variable_qr}}
The big problem is that the Initial value comes into the response and not the Current value.
Is there a possibility/script to get the Current value in the response?
Or is it possible to update the Initial with the Current value via a script?
Or is there another solution?
I look forward to a solution.
Thanks
Victor
w4dd325
(w4dd325)
June 19, 2022, 10:52pm
2
Hi @vvdkuij
I was trying to replicate your scenario but mine seems to pull in the current value not the initial.
Could you maybe provide some screenshots of what you have tried? and include the console log output too?
cheers.
vvdkuij
(vvdkuij)
June 21, 2022, 7:08am
3
Hi James, thank you for the comment.
These are the screenshots.
Postman version 9.19
Request gives a Response via Mock
Request:
<img width=â602â height=â135â style=âwidth:6.2708in;height:1.4062inâ id=âAfbeelding_x0020_5â src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/1/1c9f0b7c769872024bb7b90ef80b30104eab4a32.png " alt="Afbeelding met tafel
Automatisch gegenereerde beschrijving">
<img width=â588â height=â89â style=âwidth:6.125in;height:.927inâ id=âAfbeelding_x0020_4â src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/c/c1c54d7c9b35aef323cac0fd094756d185c6f820.png " alt="Afbeelding met tekst
Automatisch gegenereerde beschrijving">
Example Body:
<img width=â454â height=â216â style=âwidth:4.7291in;height:2.25inâ id=âAfbeelding_x0020_3â src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/f/f4f4632f0f3d0c7d818b10efb6214b84c1eda52a.png " alt="Afbeelding met tekst
Automatisch gegenereerde beschrijving">
Executing the request fills the Current value:
Environment variables
<img width=â601â height=â101â style=âwidth:6.2604in;height:1.052inâ id=âAfbeelding_x0020_2â src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/getpostman/original/2X/6/6c8d3a66e79ec8e6e7769604caf8993caf111d1a.png " alt="Afbeelding met tafel
Automatisch gegenereerde beschrijving">
But I get the Initial value in my response:
I want 111111;111111 (Current value) in the resposne and not 1234 (Initial value).
w4dd325
(w4dd325)
June 21, 2022, 9:30am
4
Ahhh I see now. Yeah, I donât think you can pass âcurrentâ variables to a mock server;
(If anyone wants to correct me on this, Iâd be really intrigued by the solution).
There is a thread here with a similar scenario;
Short Story
You have to have your environment variables set in the init value columns if you want the mock server to see them.
Long story
So, this took me a while to figure out why I couldnât make the whole mock envâs work ⊠and as it makes sense once I thought about ⊠I thought I would pass it along here so that others might not have the same issue I have
So, first off, I tend to not use the environment variables like others seem to I set all my environmentâŠ
And in here they discuss;
That got me thinking along the right track and it ALL came clear ⊠the current variables CANâT be shared with the mock server cause they arenât serialized or stored on the postman servers.
vvdkuij
(vvdkuij)
June 21, 2022, 9:56am
5
Ok, thatâs clearâŠ. very unfortunate.
Is there really no script that passes the value of a Current variable to an Initial varibale?