I am VERY new to REST API. I have an issue where I have to create a list, (already done through the GET command). From this list, (disk array volumes), I need to identify specific volume numbers, and from those “hits”, modify (using PUT), the volume label.
You could search your JSON response by using something like this;
//Parse the JSON response
const jsonData = pm.response.json();
//Find the first element in the provided array that have ldevId 140
let result = jsonData.find(a => a.ldevId === 140)
//Set label as a collection level variable
pm.collectionVariables.set("label", result.label);
//Output label to console
console.log(result.label);
However, I’m not 100% sure how you intend on using/modifying this ‘Label’ value?
(Are you ‘PUT-ing’ just the label value or re-sending the entire JSON response back to the server?
If you are simply adding a string to the label, you could do something like this;
//Set label as a collection level variable and add _XYZ to the end
pm.collectionVariables.set("label", result.label + "_XYZ");
//Output label to console
console.log(pm.collectionVariables.get("label"));
Once this has been saved into the collection variables, you could call it inside your PUT.
If you need the entire JSON response (the object retrieved by ‘find’), then try this;
//Parse the JSON response
const jsonData = pm.response.json();
//Find the first element in the provided array that have ldevId 140
let result = jsonData.find(a => a.ldevId === 140)
//Show original values
console.log(result);
//Change the label to something else
result.label = "My new label";
//Output the modified JSON response
console.log(result);