Global variable doesn't change in newman


#1

Hi!

I’m running a pre-request script on the level of a folder in which I get a login token. The code looks like this:

    pm.sendRequest({
    url: getIdentityServer(),
    method: 'POST',
    header: {
        'Content-Type': 'multipart/form-data'
    },
    body: {
        mode: 'formdata',
        formdata: [
            {key: "client_id", value: client_id, disabled: false, description: {content:"", type:"text/plain"}},
            {key: "client_secret", value: client_secret, disabled: false, description: {content:"", type:"text/plain"}},
            {key: "scope", value: scope, disabled: false, description: {content:"", type:"text/plain"}},
            {key: "grant_type", value: grant_type, disabled: false, description: {content:"", type:"text/plain"}}
        ]
    }},function (err, res) {
    var response_json = res.json();
    var access_token = response_json.access_token;
    pm.globals.set('global.access_token', access_token);
});

When I run this in postman, everything is working just fine! But when I run this in newman it doesn’t work. I can see the request going out, and getting back a 200, but the next request gets a 401, indicating the missing token.
I outputted the token as the name of a test, for verification, and could confirm that it doesn’t change.

Is there anything i’m missing?
My command of running newman:

node_modules\.bin\newman.cmd run collection.json --environment environment.
json -g globals.json --folder "Automated Tests" -r teamcity  --suppress-exit-code