Saving variables in post-request script are not consistent

Hi,

Since latest update (11.61.9) variables are not saved anymore, they are sometimes but in most cases they are not.

I can save some variables in post-request script in to collection variables, i can also verify that its saved by checking with console.log(pm.collectionVariables.get(‘someVariableName’)) at the very end of post-request script, but then after request fully ends this variable is just wiped out, i can also verify it by adding console.log(pm.collectionVariables.get(‘someVariableName’)) at the top in pre-request script of next request and console output will be empty.

Example:

Object is saved to collection variables at the end of post-request script (30)

Then at the start of pre-request script of next request same variable is empty.

image

Nothing is overwriting/resetting anywhere.

Sometimes variable is saved correctly, like after sending request 20+ times, one time it will randomly save correctly.

It was working for past 2 years+ but this week is not working anymore with no code changes.

Please help

3 Likes

Hey @lednik :waving_hand:t2:

Could you share the full script showing how these variables are being set during the execution?

Do you have any scripts are any other level that could be clearing these?

Im can save them in 3 different ways, noone of them arent working anymore since this week.

  1. Saving through collection’s utils class in pre-request script:

Object.prototype.utils = (pm) => {

function setVar(varName, varValue) {

    pm.collectionVariables.set(varName, varValue)

}

function getVar(varName) {

    return pm.collectionVariables.get(varName)

}

….

return {

    setVar,

    getVar,

Then in requests pre/post requests calling utils.getVar / utils.setVar

  1. Saving them directly inside of post-request script through helper methods:
    function setVar(varName, varValue){

    pm.collectionVariables.set(varName, varValue)

}

function getVar(varName){

return pm.collectionVariables.get(varName)

}

Then calling them by getVar / setVar

  1. Direct saving to collectionVariables:

pm.collectionVariables.set(‘someVariableName’, value)

pm.collectionVariables.set(‘someVariableName2’, value2)

all 3 different approaches were working before, but now none of them is consistent anymore.

Outside of this issue, I would recommend using the package library for any reusable utils that you might need to, they method you’re using is a workaround that was using before this feature was introduced.

Do you have a recording of this happening or anything so that we can see what’s happening on your side? As it’s an intermittent issue for you, it’s difficult for us to reproduce that on our side. :cry:

Its still working fine in postman Canary (Version 11.2.14-canary01, UI Version 11.2.14-ui-canary240621-0734) on same collections as in Postman app and Postman Web

I cant show collection publicly since its a work collection, is there any option to message you private with video comparison from Postman and Postman Canary ?

1 Like

Hey, jumping in here. I’m having the exact same problem. I built several scripts all designed to run, get a response, and save the response data value (.id) in a collection variable. all of these scripts are in a single collection.

when i run the collection once, i get a collection variable with a value, most of the time. i had to add a console.log statement and now i get the variable value every time, when I only run the collection with ONE iteration.

however if i run the collection with multiple iterations, say 3 times, i get the collection variable to show up, but no value is being populated in my collection variables. I need these value so I can reference them in additional scripts I have in a different collection.

in the attached, the first 2 collection variables were generated using a collection runner that ran 2 iterations.

the 3rd record, was me running the collection once, but didn’t have the console.log statement

the next two were me running the collection only once, each time, after i added the console.log statement

the last 3 was me again running a collection with 3 iterations.

the variables are being created, but the variable values are missing

here my post-script code that sets these collection variables

let currentCounter = pm.environment.get("prop_exists_counter");

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

console.log(data.id);

    pm.collectionVariables.set("exists_prop"+currentCounter+"_id", data.id);

if( currentCounter && currentCounter > 0 ){

    currentCounter = parseInt(currentCounter, 10);

    currentCounter = currentCounter + 1;

    pm.environment.set("prop_exists_counter", currentCounter);

   }

I built this script 3 years ago and it’s been working fine. the last time i used it was Dec 2024 (9 months ago) and it was working then. but now, i need to run them again, and it just doesn’t work any more. i did make a few changes like adding the response.text() cause my original approach was depreciated. but generally speaking, i feel these scripts should be working.

please advise if I’m doing something wrong and or how do i fix this.

I am experiencing nearly same problem. I am looking for solution from last 5 days.

1 Like

I also didnt find solution yet, my guess is if collection is big and responses that post-request needs to process are also very big in size then saving variables starts failing… and not just collection variables, also globals and environment.

Its still works fine in Postman Canary where there is still old collection’s variables tab, it might also be when they introduced auto save feature for requests - which i disabled it but you cannot disable collection’s level of changes. But since auto save is also in Canary i think new variables tab is the problem. Something definitely went wrong with updating variable tab a few weeks ago.

Im kinda disappointed especially because i cannot even downgrade Postman version. I have no idea what i will do if those same changes will also came to Canary.

1 Like

I have this issue too, it’s an absolute basic request to get an access token.

No collection or multiple requests. Only since latest update where we lost the intial value option.

Used postbot to confirm the post-response script. It even has a test to confirm the response value is set to the environment, and then i print to console. All good. But opening the environment tab and it’s not updated. Tried another request to use the variable in case it was a UI thing and it’s printing blank too.

const response = pm.response.json();

// Check if the response has the access_token
pm.test("Access token exists in response", function () {
    pm.expect(response.access_token).to.exist;
});

// Save the access_token to an environment variable
pm.environment.set("access_token", response.access_token);

// Confirm that the access_token environment variable has been updated
pm.test("Access token environment variable is updated", function () {
    pm.expect(pm.environment.get("access_token")).to.equal(response.access_token);
});

// Output the access_token environment variable to console
console.log("Access token:", pm.environment.get("access_token"));

Test results: both PASSED

passedAccess token exists in response

passedAccess token environment variable is updated

1 Like

I’m seeing the exact same issue on both the desktop app and web app (11.65). I’m setting a collection variable (pm.collectionVariables.set()) in the post-response script, and haven’t tried with any other types. The variable is always created, but sometimes the value is blank.

// post-response script for request "A"
const xsrfToken = pm.cookies.get('xsrfCookieName');
console.log('value: ' + xsrfToken); // confirms the value exists
pm.collectionVariables.set('token',xsrfToken);
console.log('variable val: ' + pm.collectionVariables.get('token'); // returns the token value 

If I now look at the collections Variables tab, the variable token will be there, but the value may or may not be blank. Doing a console.log of the variable in a subsequent request is another way to check.

1 Like

Same issue on my side. @postman-drop when fix could be prepared? It is serious bug

1 Like

I have same issue, using 11.65.4 updated on 3rd Oct.

pm.collectionVariables.set used in post-request does not store value update, null is stored. The updated value cannot be recalled from different request.

pm.globals.set and pm.environment.set are still working.

pm.collectionVariables.set used in pre-request is still working.

Any news on fix?

When will this be fixed? pm.collectionVariables.set is not stored in the collection. Please fix this asap.

1 Like

It looks like they don’t care too much. Many people having the same issue (same for me here) and no answer or follow-up from the team.

1 Like

Hey folks :wave:,

I’m really sorry if it’s felt like we don’t care about this issue or others you’ve been facing, that’s definitely not the case. We really appreciate you taking the time to share your experiences.

Because this is a general user forum, some topics can unfortunately get pushed down as new ones come in, and that can cause things to be missed. I completely understand how frustrating that feels, and I want to make sure we look into this properly.

To help us understand what’s going on, I’ve put together a really simple example (in the latest version) showing how storing Collection Variables via a script is working for me:

If what you’re seeing is different, could you please share a short recording or more details about your setup? So far, I haven’t been able to reproduce the issue.

Also, just a quick note for product bugs, it’s best to log them directly through our GitHub issue tracker. That route gets reports in front of the development team faster :folded_hands:

hi @danny-dainton I sent you personal message with YT video. Please review it.

I guess the problem starts happening on bigger sized responses/scripts, what you tested it is the most simple happy-path example, ofc its gonna work fine, but when things getting scaled up it starts breaking.

Thank you

Hey @lednik

Thanks so much for sharing that video, I really appreciate you taking the time to do that. :heart:

My example was intentionally simple, as I was trying to identify the specific conditions that might help us replicate the issue you’re seeing. A few others in the thread have mentioned they are experiencing the same problem, but there hasn’t been much detailed information to go on yet.

Since everyone uses Postman a little differently, it’s possible there may be more than one factor contributing to what’s happening here.

I’ve watched your video and shared it with our development team so they can investigate further. I’ll share any updates as soon as I hear back from them.

1 Like

Same issue here guys, thanks for the follow up, waiting for a possible fix soon, greetings! :+1:

Apparently uninstalling and reinstalling (sometimes multiple times) the Postman App for MacOS Tahoe 26.1 (25B78) resolve this issue:

Postman Version 11.71.3
UI Version: 11.71.3-ui-251112-0111
Desktop Platform Version: 11.70.6 (11.70.6)

You can also try removing any possible residual cache located at: “Users/<your_user>/Library/Application Support/Postman“

At the moment, this appears to be the only available fix. Before doing so, make sure to share your collection variables to create a backup in the Postman Cloud.

CC @danny-dainton

Hello @danny-dainton , I use Version 11.72.0
UI Version: 11.72.0-ui-251117-0112
Desktop Platform Version: 11.71.7 (11.71.7)
And I notice that variables are no longer saved/updated in real time.

I have checked both Mac and Windows and experience is the same.

I logged the saved variables in console and I could see the value for each of the variable. But the value was not populated.