I’m using quite intensively Postman in my day-to-day work and I’m really found of the new Visualize API responses feature.
It’s good that this feature use Handlebars but the issue is that the basic helpers are quite simple and generally with Handlebars, you add your own helpers in order to full control your output (string format for example)
Do you know if there is a way to register helpers with new visualizer?
Currently, there’s no way to register custom Handlebars helpers but we’ll consider this as a feature request. Can you specify your use case and create a feature request on our GitHub issue tracker?
If possible, we will add a few common helpers by default.
The feature request was made on 23sep2019. Give it a thumbs up if you’d like to see Handlebars.registerHelper support added to Postman’s Visualization feature.
Here’s a (really bad) work-around I’m doing since Helpers aren’t available. Sharing here (and in the Git request). Another option is to customize the full response, and just pass that in with all the changes.
Display my timezone as a hover “title” attribute on the UTC timestamp field:
let template = `
<table class="table table-dark">
<tr>
<th>UTC Timestamp (hover for MST)</th>
</tr>
{{#each response}}
<tr>
<!-- Get the formated Time from mstTimes array, for this current index -->
<td title="{{lookup ../mstTimes @index}}">{{timestamp}}</td>
</tr>
{{/each}}
</table>
`;
let mstTimes = [];
// Loop over response
for (let resp in pm.response.json()){
// For each loop index, convert timestamp to my timezone
mstTimes.push(new Date(Date.parse(pm.response.json()[resp]["timestamp"])).toLocaleString("en-US", {timeZone: "America/Denver"}));
}
// pass mstTimes to template
pm.visualizer.set(template, {response: pm.response.json(), mstTimes: mstTimes});
I was also hoping for helpers to be available. I simply want to loop over a list. Since the index starts from 0, a handlebar helper to increment would be extremely useful.