Performing a GET request that returns in XML format. I converted that to JSON as outlined below. I am looking to parse an array and set an array as a env. variable for each specific object in the array.
How can I achieve looping through Tuple.Answer to get all highlighted values for each object from the response? With the current test scripts I am getting the following in my ActionIDs env variable:[“1965555”,“1965555”,“1965555”,“1965555”,“1965555”,“1965555”]
Path to data I want to retrieve:
BESAPI.Query.Result.Tuple.Answer[0]._
Here is my action script:
var jsonData = xml2Json(responseBody);
var ActionIDs = ;
.each(jsonData.BESAPI.Query.Result.Tuple[0].Answer[0]., () => {
ActionIDs.push(jsonData.BESAPI.Query.Result.Tuple[1].Answer[0]._)
})
pm.environment.set(“ActionID”, ActionIDs.shift());
pm.environment.set(“ActionIDs”, JSON.stringify(ActionIDs));
pm.test(“Status code is 200”, function() {
console.log(pm.response.code);
pm.response.to.have.status(200);
});
Response:
<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
<Query Resource="(id of it, name of it, state of it) of bes actions">
<Result>
<Tuple>
<Answer type="integer">1965354</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (1/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965555</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (2/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965761</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (3/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965962</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (4/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967153</Answer>
<Answer type="string">Image: Windows Images: (1/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967354</Answer>
<Answer type="string">Image: Windows Images: (2/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967555</Answer>
<Answer type="string">Image: Windows Images: (3/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967756</Answer>
<Answer type="string">Image: Windows Images: (4/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967957</Answer>
<Answer type="string">Image: Windows Images: (5/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1968158</Answer>
<Answer type="string">Image: Windows Images: (6/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
</Result>
<Evaluation>
<Time>8.844ms</Time>
<Plurality>Plural</Plurality>
</Evaluation>
</Query>
</BESAPI>