I’m using an html template within the Tests tab to output my json data, however, some of the data is in timestamp form. Namely, the date_created, first_seen, & last_seen are all being returned in timestamp form. Is there a way to do the calculation to a more standard date/time format from within the var template ? I’ve tried several ways to convert the timestamp, but none work within the template variable or cause the call to fail. Is it even possible to do within that template? Or how would you do it outside the template and then pull it back into the html? Because of the each loop I’m just not sure how to do this.
The other thing to keep in mind is the number of number of results can vary, so it’s not a fixed number of results I can hard code.
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;}
.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>
Dom: {{response.result.dom}}</br>
Rep: {{response.result.rep}}</br>
Reg: {{response.result.reg}}</br>
Date Created: {{response.result.date_created}}</br>
First Seen: {{response.result.first_seen}}</br>
Last Seen: {{response.result.last_seen}}</br>
<table class="tftable" border="1">
<tr>
<th>Name</th>
<th>Rep</th>
<th>First Seen</th>
<th>Last Seen</th>
</tr>
<tr>
</tr>
{{#each response.result.ns}}
<tr id=row_{{@key}} onClick="handleClick(this.id)">
<td id={{@key}}>{{host}}</td>
<td>{{rep}}</td>
<td>{{first_seen}}</td>
<td>{{last_seen}}</td>
</tr>
{{/each}}
{{#each response.result.send}}
<tr id=row_{{@key}} onClick="handleClick(this.id)">
<td id={{@key}}>{{id}}</td>
<td></td>
<td></td>
<td>{{last_seen}}</td>
</tr>
{{/each}}
</table>
`;
pm.visualizer.set(template, {
response: pm.response.json()
});
The JSON response is like:
{
"code": 200,
"result": {
"dom": "abc",
"rep": "green",
"reg": "Going",
"date_created": 1311292800,
"first_seen": 1339185300,
"last_seen": 1661781780,
"ns": [
{
"host": "aws",
"first_seen": 1517597640,
"last_seen": 1661781780,
"rep": "green"
}
]
}
}