I am trying to extract a value from a successful API request, which is sending a XML response, using Postman. Following is the way how I tried to catch the value that I need from the response.
var jsonObject = xml2Json(responseBody);
console.log(jsonObject);
postman.setGlobalVariable("Active_SAML", jsonObject.bankidCollectResponse.SAMLReferens);
console.log(pm.globals.get("Active_SAML"));
That script written inside "Tests" tab and the console log out put is as below.
But when I execute the program, I get following error.
There was an error in evaluating the test script: TypeError: Cannot read property 'SAMLReferens' of undefined
I am not sure where I'm doing it wrong. Can anybody please point out me that?
Thanks to @ChathurangaChandrasekara comment, I did able to figure out the format that they expected.
// Convert XML output to JSON format
var jsonObject = xml2Json(responseBody);
// Since the converted JSON format is having Envelope and Body tags we need following format
var activeSamlVal = jsonObject['SOAP-ENV:Envelope']['SOAP-ENV:Body'].bankidCollectResponse.SAMLReferens;
console.log(activeSamlVal)
// Assigning the extracted value in to a global variable
pm.globals.set("SAML_key", activeSamlVal);
console.log(pm.globals.get("SAML_key"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With