In the following postman pre request script, I need to call multiple requests before I make an actual postman request.
Firstly, it will call session API to retrieve the session id
After session id is success only, then I need to call customer signon to make the user logged in.
So I did the following changes in my postman prerequest script but some how the LocalSessionId in the customer signon request is undefined.
const sessionRequestData = {
url: "http://myurl.com/session",
method: 'POST',
header: { 'content-type': 'application/json' },
body: {
mode: 'raw',
raw: JSON.stringify({
"device": {
"id": "web",
"type": "WEB"
}
}
};
pm.sendRequest(sessionRequestData, function (err, res) {
var jsonData = res.json();
if (err) {
console.log("mailman: error retrieving session id"+err);
}
else {
console.log("mailman: retrieved session data succesfully"+ jsonData.session.id);
pm.variables.set("LocalSessionId", jsonData.security.session.id);
}
});
const customerSignonRequestData = {
url: "http://myurl.com/CustomerSignOn",
method: 'POST',
header: { 'content-type': 'application/json' },
body: {
mode: 'raw',
raw: JSON.stringify( "customerRequest": {
"identities": {
"identity": [
{
"data": "sessionId",
"value": `${pm.variables.get("LocalSessionId")}`
}
]
}
});
pm.sendRequest(customerSignonRequestData, function(err, res){
console.log("customer sign on request "+ JSON.stringify(customerSignonRequestData.body.raw))
var jsonData = res.json();
if (err) {
console.log("mailman: unable to signon"+err);
} else {
console.log("mailman: login successful"+ JSON.stringify(jsonData))
}
});
Can anyone suggest how can I make sure that the customer signon is called after the session is retrieved only.