postman 全局变量设置

设置全局变量

方法一:

导入环境变量的json文件

home--Environments--Globals--import--select json feil

方法二:

Collections-API-Pre-request Script- dev getToken code

const getAmtoken = {
url: 'https://cmb-staff-dsp-uat.hk.hsbc:8443/dsp/json/realms/root/realms/staff/authenticate?authIndexType=service&authIndexValue=TestTree',
method: "POST",
header: [
'X-OpenAM-Username : 43872156',
'Accept-API-Version:resource=2.0,protocol=1.0'
]
};

const jar = pm.cookies.jar();

pm.sendRequest(getAmtoken , function (err, response) {
if(err){
console.log('Get amtoekn err:',err);
}else{
var amToken = response.json().tokenId;
pm.globals.set("amtoken",amToken);
pm.sendRequest(e2eRequest(amToken), function (err, res) {
// clear cookies
jar.clear('https://cmb-staff-dsp-uat.hk.hsbc:8443/dsp/rest-sts/staff/tokenTranslator?_action=translate')
if(err){
console.log('Get e2e token err:', err)
}else{
pm.globals.set("e2etoken", res.json().issued_token);
}
});
}
});

function e2eRequest(amtoken){
return {
url: 'https://cmb-staff-dsp-uat.hk.hsbc:8443/dsp/rest-sts/staff/tokenTranslator?_action=translate',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'raw',
raw: JSON.stringify(
{
"input_token_state": {
"token_type": "SSOTOKEN",
"tokenId": amtoken
},
"output_token_state": {
"token_type": "JWT"
}
}
)
}
}
}
posted @ 2022-02-26 10:15  苍耳冬阳  阅读(170)  评论(0编辑  收藏  举报