Extracting data from response and validating it

I want to write a test in postman to validate data inside pli:GuidSequenceID that it is guid and is not null or 0. How can I access that data from side that tag and validate it that if it is the in GUID format or not. I am getting the response in xml format.

<?xml version="1.0"?>

<pli:ResponseHeader overallResult=“success”>
nax:VendorNameSome Name</nax:VendorName>
pli:JoSequenceIDBUL 000001 10001 0000050</pli:JoSequenceID>

<pli:PromptForJooyaltyFlag value=“no” />

trying this approach for solution but not working as I am getting error saying
" TypeError: Cannot read property ‘pli:LoyaltySequenceID’ of undefined "
pm.test(“Converting xml to json”, function () {
var jsonData = xml2Json(responseBody);
console.log(‘JSON response’, jsonData);
let LoyaltyID = jsonData[‘pli:GetJooyaltyOnlineStatusResponse’][‘pli:ResponseHeader’][‘pli:JooyaltySequenceID’];
console.log('LoyaltyID is : ', LoyaltyID);


From the solution you posted I wasn’t sure if you were trying to get the pli:JoSequenceID or the pli:GuidSequenceID, so in my solution I just used both. When I run this locally in a mock with the example response you provided it all passes.

//Convert XML response to JSON
var jsonData = xml2Json(responseBody);
console.log("JSON response", jsonData);

//Get JoSequenceID value
var JoSequenceID = jsonData["pli:GetJooyaltyOnlineStatusResponse"]["pli:ResponseHeader"]["pli:JoSequenceID"];
console.log("JoSequenceID is", JoSequenceID);

//Test JoSequenceID is not null
pm.test("JoSequenceID is not null", function () {

//Test JoSequenceID is not 0
pm.test("JoSequenceID is not 0", function () {

//Get GuidSequenceID value
var GuidSequenceID = jsonData["pli:GetJooyaltyOnlineStatusResponse"]["pli:ResponseHeader"]["pli:GuidSequenceID"];
console.log("GuidSequenceID is", GuidSequenceID);
var regex = /^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/;

//Test GuidSequenceID is not null
pm.test("GuidSequenceID is not null", function () {

//Test GuidSequenceID is not 0
pm.test("GuidSequenceID is not 0", function () {

//Test GuidSequenceID is a GUID
pm.test("GuidSequenceID is a GUID", function () {


1 Like