How to run one request from another using Pre-request Script in Postman

后端 未结 6 1300

I\'m trying to send an authenticated request with one click in postman.

So, I have request named \"Oauth\" and I\'m using Tests to store the token in a local variable.

6条回答
  •  情深已故
    2021-01-31 02:44

    As mentioned by KBusc and inspired from those examples you can achieve your goal by setting a pre-request script like the following:

    pm.sendRequest({
        url: pm.environment.get("token_url"),
        method: 'GET',
        header: {
            'Authorization': 'Basic xxxxxxxxxx==',
        }
    }, function (err, res) {
        pm.environment.set("access_token", res.json().token);
    });
    

    Then you just reference {{access_token}} as any other environment variable.

提交回复
热议问题