i want to get the values DODATEST01 and DODATEST02 to generate variables to change them later in another postman command.
I think the challenge here is the multiple keyword “mpsk-key” that prevails to generate a variable for each entry because there are multiple matches ?
Maybe someone had a similar problem in the past and have already a Solution for that ?
bye Markus
You should be able to loop over the data and extract those values from the keys inside the array. There are a number of different topics on the forum that will give you some solutions of how to do this - This is more of a Javascript problem than a specific Postman problem, learning a few basics of that language will help you to create scripts in Postman with ease.
Alternatively, With the introduction of Postbot, you have the capability to ask it those types of questions. Here’s I’m using a basic prompt that returning me some basic code that I could use to do this. I’m using the Postman Echo service here so some of the references to the response data would be different on your side.
// Get the data object from the response
data = pm.response.json().data;
// Extract the values of the mpsk-key keys from the mpsk-key array
mpskKeys = data['Cisco-IOS-XE-wireless-wlan-cfg:mpsk-keys']['mpsk-key'];
// Store the mpsk-key values in individual global variables
mpskKeys.forEach(function(key, index) {
pm.globals.set("mpskKeyValue_" + index, key['mpsk-key']);
});
This is making those values individual variables but this could be amended to push all the values into an array, which would make it easier to use them in other requests, as it would be under a single variable key and not loads of unique global variable names.