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