Reputation: 9495
I am trying to Visualize my SOAP envelope in Postman into a simple table using the docs provided here and here.
Here is what my payload looks like:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>urn:uuid:e0817ed7-6575-4b05-8af4-0aa66bc3a428</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:49866f4c-0c5f-4d8e-b11d-cc194878215b</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-a0a30316-f6c4-4a36-bb48-13af93f451c6">
<wsu:Created>2020-03-11T17:14:16Z</wsu:Created>
<wsu:Expires>2020-03-11T17:19:16Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</env:Header>
<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<OverallStatus>OK</OverallStatus>
<RequestID>83222ed5-75a0-4ac0-8bb3-e3f76fdf89f9</RequestID>
<Results xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true"/>
<ObjectID xsi:nil="true"/>
<Type>DataExtensionObject</Type>
<Properties>
<Property>
<Name>key</Name>
<Value>11223344</Value>
</Property>
<Property>
<Name>status</Name>
<Value>pending</Value>
</Property>
</Properties>
</Results>
<Results xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true"/>
<ObjectID xsi:nil="true"/>
<Type>DataExtensionObject</Type>
<Properties>
<Property>
<Name>subscriberkey</Name>
<Value>334455</Value>
</Property>
<Property>
<Name>status</Name>
<Value>sync_failure</Value>
</Property>
</Properties>
</Results>
</RetrieveResponseMsg>
</soap:Body>
</soap:Envelope>
This is what I have so far in my Test script:
var template = `
<table bgcolor="#FFFFFF">
<tr>
{{#each}}
<td>{{header name}}</td>
{{/each}}
</tr>
{{#each}}
<tr>
<td>{{value}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json()
});
What I'm trying to do is dynamically generate all the header columns from the Results > Properties > Property > Name
and have the values rows propergate from Results > Properties > Property > Value
.
Is this possible?
Upvotes: 3
Views: 1157
Reputation: 25881
This is seriously horrible but it would create a table with the data you need and maybe you can refactor it after:
// Convert the XML to JSON
let jsonData = xml2Json(pm.response.text());
// A nasty looking reference to the Results array
let resultsArray = jsonData["soap:Envelope"]["soap:Body"].RetrieveResponseMsg.Results
// Handlebars syntax for displaying the keys/values you want
var template = `
<table style="background-color:white";>
<tr style="background-color:#d1d1e7;">
{{#each response}}
{{#with Properties}}
{{#each Property}}
<td>{{Name}}</td>
{{/each}}
{{/with}}
{{/each}}
</tr>
<tr>
{{#each response}}
{{#with Properties}}
{{#each Property}}
<td>{{Value}}</td>
{{/each}}
{{/with}}
{{/each}}
</tr>
</table>
`;
pm.visualizer.set(template, {
response: resultsArray
});
Upvotes: 2