Saving variables in post-request script are not consistent

Hey, guys! I’ve been experiencing the same problem for several days. Over time, my collection and the number of variables have grown and now it has become a little more complex and there is more data, perhaps that’s why the variables that are rewritten by post-scripts do not change periodically when I make several requests in a row.
Postman for Windows

Version11.72.1

UI version

11.72.1-ui-251117-0605

Desktop platform version

11.71.7

Architecture

x64

OS platform

win32 10.0.19045

Issue was reported first on 5th of Sep and today is 19th of Nov, so after more than 2 months no fix was provided.

Hey everyone :waving_hand:,

I understand and appreciate how frustrating this situation has been for you. Thank you so much for bearing with us.

Our team has identified the issue and is working carefully on the fix. Once it has been fully tested, we are aiming to release an updated version early next week. :folded_hands:

I will update this thread if and when we have more information to share.

2 Likes

Hey everyone! Thanks so much for reporting this issue — and sorry for the delay! We’ve just released a fix in Postman app 11.72.7, so please go ahead and update to the latest version.

If you’re still seeing any problems, feel free to reach out. We’re here to help!

1 Like

Hello Ankur.

The 11.72.7 release you mentioned is a lower version compared to the version I currently use (11.73.0).

I’m trying to understand how the said version is to be a fix.

More so, I just ran an update check and saw a version 11.73.1 available which after installation and checking the reported issue, the issue still persist.

Hi @ankur-dengla @danny-dainton , for my use case, it’s working again. I’m currently at 11.73.1 and i cannot reproduce my issue again. Will do more testing and update this thread if issue will reappear. Thank you for support.

1 Like

Issue still reproducible for me.


Version11.73.1

UI version 11.73.1-ui-251125-0111

Desktop platform version 11.72.9

Hey @OluwafemiOlawale @AlexandruN2!

Sorry to hear that the issue is still not resolved for you. In order to help us point out the root cause better, could you please share -

  • A screen recording of your workflow?
  • Also, the collection / script that is causing the issue (if possible)

Still reproducible on macOS with Postman 11.73.2.

I see this more often with JWT that is fetched and stored in a Collection Var then later used in subsequent requests. Sometimes that collection var isn’t updated and it holds onto an older value. These are long tokens, spanning many number of lines, as seen in the Collection Var value field in the UI. Maybe this has something to do with it, no idea.

This is easy to see with console logging. It doesn’t happen all the time but is unreliable enough that we’ve moved to another tool for the time being. The flow is simple. One request w/ pre and post scripts, and one collection var, is all that’s needed to demo it. (I can’t provide screenshots or code here of my examples directly however, except for that showing console output below.)

  1. In pre-request script of request to fetch JWT, fetch its current value that is stored in Collection Var. Print it to the console.
  2. In post-response script, store the new value of that JWT (taken from response body of the request) in that same var. Print the value the console. It should be different than the above current value (and always is, from what I’ve seen).

Step (1) and (2) happen with each single click of the request’s Send button, of course. The expectation is that the current value shown should be the SAME as the immediate previous new value that was retrieved on the prior click of Send. Sometimes it simply isn’t.

1 Like

It seems to be fixed now. But I lost all my variables. :angry:

image
Here is a console log of what I was expecting to be in my environment varibale ‘sessionId’.
However, for every call I make that variable is never updated unless I manually copy and paste.

pm.environment.set(“sessionId”, expected?.manageCred ?? “”); is what I use to save the variable @ankur-dengla .
Cc: @danny-dainton

Hello @danny-dainton , I also notified you in my response here.
Issue persist.

Hello
For last couple days I am facing same problem with environment variable not set.
Currently I am o Postman v11.73.5 - the latest version.

Scripts used to set it correctly in past - but not any more.
Is there an estimated timeframe for the fix to be ready?

Hey @marsjan :waving_hand:t3:

Welcome to the Postman Community :postman:

Could you expand more on the context of what your script is doing, please?

Providing script examples and more information will be really useful in narrowing down the issue. :folded_hands:

I have the same issue with global variables in Version 11.74.0.

All global variables worked fine for a long time, but recently, after another run, the tests failed; it turned out the variables were truncated.

I found a complete old file with an export of my variables, but when importing them into the current version, they are all truncated. In addition, if you select the three dots in the menu - unshare all, the variable values ​​are completely deleted.

I am having the same issue in v11.74.2.
But I think I might have found a correlation between the problem occuring and it not occuring, at least on my end.

When the ‘[Collection] (screen) > variables (tab)’ is open (in the background), or if the ‘[Collection] (screen) > variables (tab)’ has been opened in an open ‘[Collection] (screen)’ instance, setting collection-variables won’t work.

When the ‘[Collection]’ screen is not open, or an open ‘[Collection]’ screen instance hasn’t opened the ‘variables’ tab, setting collection-variables does seem to work.

This was tested in a workspace with only one collection, so I am unsure about multiple-collection workspaces.
I have only tested this for collection-variables, so I am unsure about other types of variables.

The post-response script I am using:

if (pm.response.status != "OK") // 200.
{
    console.warn('auth request failed, not updating collection-variables.');
    return;
}

var variableName = 'accesstoken';

var responseObj = JSON.parse(pm.response.text());

// Note: In Postman v11.74.2, setting a variable while the '[collection] > variables' screen is open, or the '[collection] > variables' screen has been opened in the '[collection]' screen instance, the value won't be saved.
// Bug tracking page: https://community.postman.com/t/after-latest-update-saving-variables-in-post-request-script-are-not-consistent-anymore/84370/36.
await pm.collectionVariables.unset(variableName);
await pm.collectionVariables.set(variableName, responseObj.access_token);

The ‘[Collection] (screen) > Variables (tab)’ is referring to the following tab:

I am also having the same problem with environment variables. Script is very straightforward, it prints the same token for the console.logs but environment is not set really. It was working before of course.

console.log(pm.response.text());

if (pm.response.code === 200) {
    var jsonData = pm.response.json();
    pm.environment.set('token', jsonData.token);
    pm.environment.set('refreshToken', jsonData.refreshToken);
    console.log('token: ' + jsonData.token);
    console.log('variable:' + pm.environment.get('token'));
}

Version 11.74.4
UI Version: 11.74.4-ui-251204-0111
Desktop Platform Version: 11.74.4 (11.74.4)

Hey @security-geoscienti5 :waving_hand:

Welcome to the Postman Community! :postman:

It’s tricky to tell from this but do you also have an active environment set, when running that script? I can see the variable UI but not if that’s set during the execution.

Is it setting outside of that if statement, when you have a single variable set command?

Have you signed out and in again since you updated?

Do you work in a Team with other people on Postman?

I started having this problem around 10 days ago, and it’s still happening for me on version 11.74.4 (Windows version). I have a post-response script that is setting an environment variable called ‘session_id’. There are no global variables, and no collection variables with the same name. In the script if I use console.log to output the variable after setting it with pm.environment.set, then the console shows the correct (new) value of the variable. However when I then open the environment variables screen, the variable is showing the wrong (old) value.
I did fix the issue a few days ago by completely uninstalling Postman and re-installing, but it has now started happening again.

UPDATE: I’ve just tried signing out of my Postman account, restarting Postman and signing in again, and it’s working again (for now).

We are working in a team. They are selected of course. If I set a dummy token like this it works. Also I’ve checked the condition of status by printing pm.response.code === 200 it returns true as well.

Edit: It looks like something fishy with the conditions. For example the following doesn’t work.

1 Like