How to extract a value from a response body and use it in next post body or in next call’s header. Here is the script snippet,
"page_2 - https://login.np.v1/authorize",
function () {
response = http.get(
"https://login.np.v1/authorize",
{
headers: {
"upgrade-insecure-requests": "1",
"sec-ch-ua":
'"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
},
}
);
const stateToken1 = findBetween(JSON.stringify(response), 'stateToken=', '\'');
console.log(">>>>>>>>>>>",stateToken1)
response = http.post(
"https://login.np.mediaecosystem.io/api/v1/authn/introspect",
'{"stateToken":"ObhVHBHbjhHBhBH_NH1562BHjhjhhjhywyHbhj"}',
{
headers: {
accept: "application/json",
"accept-language": "en",
"content-type": "application/json",
"x-okta-user-agent-extended": "okta-signin-widget-5.11.1",
"sec-ch-ua":
'"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
},
}
);
In the above code, I have fetched ‘stateToken’ value and save it in ‘stateToken1’. Now I want to use it in next subsequent requests. So what should I write in place of ‘ObhVHBHbjhHBhBH_NH1562BHjhjhhjhywyHbhj’ so that dynamic stateToken1 passes every time.