Visualizer: Getting a specific Nested Object. Same name, but different values

Please community! Grace me with your wealth of knowledge. Iā€™ve got hundreds of laptops Iā€™m checking the warranty on through Dellā€™s API. The response returned looks like the one below. The visualize doesnā€™t give me the endDate either. The response is only on one machine for now, but the API lets me check up to 100 machines at once. The script for the visualizer is below it. Iā€™m trying to build the visualize to only pull the ā€œproductLineDescriptionā€ ā€œserviceTagā€ and a specific ā€œendDateā€. The problem for me there is that there are 3 different ā€œendDatesā€ listed under ā€œentitlementsā€. I only want it to pull the 3rd one. Iā€™d really like to get it to work so I can run 100 at a time.

[
{
ā€œidā€: 123456789,
ā€œserviceTagā€: ā€œPOSLPTPā€,
ā€œproductLineDescriptionā€: ā€œLATITUDE 5590ā€,
ā€œentitlementsā€: [
{
ā€œitemNumberā€: ā€œ997-8328ā€,
ā€œstartDateā€: ā€œ2018-08-28T05:00:00Zā€,
ā€œendDateā€: ā€œ2019-08-29T04:59:59.999Zā€
ā€œserviceLevelDescriptionā€: ā€œOnsite Service After Remote Diagnosis (Consumer
Customer)/ Next Business Day Onsite After Remote Diagnosis (for business Customer)ā€,
ā€œserviceLevelGroupā€: 5
},
{
ā€œitemNumberā€: ā€œ984-1952ā€,
ā€œstartDateā€: ā€œ2018-08-28T05:00:00Zā€,
ā€œendDateā€: ā€œ2021-08-28T04:59:59.999Zā€,
ā€œserviceLevelDescriptionā€: ā€œKeep Your Hard Drive/Keep Your Hard Drive for Enterprise
Serviceā€,
ā€œserviceLevelGroupā€: 11
},
{
ā€œitemNumberā€: ā€œ997-8332ā€,
ā€œstartDateā€: ā€œ2019-08-29T05:00:00Zā€,
ā€œendDateā€: ā€œ2021-08-29T04:59:59.999Zā€,
ā€œserviceLevelDescriptionā€: ā€œOnsite Service After Remote Diagnosis (Consumer
Customer)/ Next Business Day Onsite After Remote Diagnosis (for business Customer)ā€,
ā€œserviceLevelGroupā€: 5
}
]
}
]

My Test Script in its original form. Iā€™ve tried dozens of ideas, so I reset it back to the beginning.

var template =`

.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
.tftable

<table class="tftable" border="1">
    <tr>
        <th>Service Tag</th>
        <th>Product ID</th>
        <th>End Date</th>
    </tr>

    {{#each response}}
        <tr>
            <td>{{serviceTag}}</td>
            <td>{{productLineDescription}}</td>
            <td>{{endDate]}}</td>
        </tr>
    {{/each}}
</table>

`;

pm.visualizer.set(template, {
response: pm.response.json()
});

Bump! I know there are some geniuses out there that can help.

Is it always the third result? Or can some devices have more or less entitlements?

If its always the 3rd object in the entitlement array, then the following should work.

{{entitlements.[2].endDate}}

The visualizer supports the Handlebars JS library.

Handlebars (handlebarsjs.com)

The Handlebars treats the array slightly differently. I had to search on how to target the array because the normal ā€˜entitlements[2]ā€™ was throwing errors.

let response = pm.response.json().data
// you can drop the .data (this is just how Postman echo returns the response)

console.log(response);

var template = `

    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;position:sticky;top:0;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">

        <tr>
            <th>id</th>
            <th>serviceTag</th>
            <th>endDate</th>
        </tr>

        {{#each response}}
            <tr>
                <td>{{id}}</td>
                <td>{{serviceTag}}</td>
                <td>{{entitlements.[2].endDate}}</td>
            </tr>
        {{/each}}

    </table>

`;

console.log(response);

pm.visualizer.set(template, {
    response: response
});
1 Like

Ok Iā€™ll give it a try! Thanks for the feedback. Iā€™ll let you know.

You have just made my day! Works exactly like I want. Thanks for the info on HandlBars JS library too.

1 Like