I want to get the user_recipient_id of the last node from the responseBody array.
This is dynamic, a new node from the last node will be added for new data in responseBody.
Sample responseBody:
[
{
"nickname": "Drew",
"user_recipient_id": 40,
},
{
"nickname": null,
"user_recipient_id": 44,
},
{
"nickname": "N3// reci",
"user_recipient_id": 126,
}
]
My code:
const responseJson = pm.response.json();
var i = Object.keys(responseJson).length;
console.log("The number of expected keys in the response body is: " + i)
postman.setEnvironmentVariable("i", i);
pm.environment.set("urid", responseJson.$[Number(i)].user_recipient_id);
console.log(pm.variables.get("urid"));
I’m getting a result of
TypeError: Cannot read property ‘10’ of undefined
due to Number(i)
in this line pm.environment.set("urid", responseJson.$[Number(i)].user_recipient_id);
Tried to parseInt as well.