const codeGetRequest = {
url: pm.variables.get(‘test-code-url’),
method: ‘GET’
};
//first get call
pm.sendRequest(codeGetRequest, function (err,res){
console.log(‘Code request sent’);
const location = res.headers.find(h => h.key == ‘Location’);
const locationValue = location.value;
pm.environment.set(‘location’, locationValue);
if(locationValue.includes('response_type')){
console.log('No Code found. User should sign in.');
}
else{
var str = locationValue.split("code=")[1];
var code = str.split("&")[0];
console.log("CODE is : " + code);
pm.globals.set('jsession_id_url', locationValue);
pm.globals.set('auth_code', code);
const jSessionIDGetRequest = {
url: pm.variables.get('jsession_id_url'),
method: 'GET'
};
//second GET call(this is the call which has the headers pre populated as the url for this call is extracted from first GET call response)
pm.sendRequest(jSessionIDGetRequest, function (err,res){
console.log('JSession ID request sent');
const cookie = pm.request.headers.get('Cookie');
console.log('COOKIE : '+cookie);
});
// POST call
pm.sendRequest(echoPostRequest, function (err, res) {
console.log(err ? err : res.json());
if (err === null) {
console.log('Saving the token')
var responseJson = res.json();
}
});
}
});
const echoPostRequest = {
url: pm.environment.get(“token-url”),
method: ‘POST’,
header: ‘Content-Type:application/x-www-form-urlencoded’,
body: {
mode: ‘urlencoded’,
urlencoded: [
{key: ‘grant_type’, value: ‘authorization_code’, disabled: false},
{key: “code”,value: pm.variables.get(“auth_code”), disabled: false},
{key: “redirect_uri”, value: pm.environment.get(“redirect-uri”), disabled: false},
{key: “client_id”,value: “client_id”, disabled: false},
{key: “client_secret”,value: “secret”, disabled: false},
{key: “user-name-attribute”,value: “sub”, disabled: false},
{key: “provider”,value: “iso”, disabled: false}
]
}
};
@allen.helton this is the pre-req script i am using.
In the second GET call, the following is returning Undefined and that is the only value i am having hard time extracting.
“const cookie = pm.request.headers.get(‘Cookie’);”