How I can rewrite collection value via Newman

Hello. How I can rewrite the value of COLLECTION variable via Newman? I have a request:

let update_ver = "true";
body = pm.collectionVariables.get('variableVersion');
let expectedBody = body;
pm.test("tryupdatevariable"+ expectedBody, function () {
     if(update_ver == "true" )
    {
        pm.collectionVariables.set('variableVersion', responseBody);
        expectedBody = responseBody;
    }
}); 

When I export JSON collection and delete the value of tryupdatevariable then running newman, newman doesn’t set value

1 Like

What you’re looking for is persisting variables after the collection run.

According to this GitHub issue, it looks like that might not have native support, but you have a workaround available.

Is it working for collection variables???

How are you running newman?

Are you giving it a json file for the collection or are you giving it the link to pull the current version of the collection?

Either way the answer is no, but we can figure out what you need to do based on your answer here.

I want to update the value of collection variable when running newman or node js

Are you passing in json or are you passing in a url for your collection?

We wanna use json, cause our developers would like to update value of collection variable. The idea is developers doesn’t use postman. Postman only for testers

If you’re passing in static json as your collection, there’s not going to be a way for you to update those variables.

Have you considered moving the collection variables to an environment instead?

Yes, I have. But it’s not a good idea, because if I wanna use this collection tests on different environments… UPD : We have decided to use global variable.