Using Postman Visualizer to Copy Results to Excel

Using Postman Visualizer to Copy Results to Excel

 

What is Visualizer?

Postman Visualizer is a tool in Postman that allows you to render the JSON responses from FOLIO in easier to understand visual formats, like tables and bar charts.

https://learning.postman.com/docs/sending-requests/visualizer/

You essentially add extra javascript code to the tests that you can run in the Postman tool to output it in different formats. 

Postman offers training and info on it on the page above, but their examples are more than a little complicated for what we might want to do. So I'm just going to detail an example of how I used this tool to output permissions information in tabular format, which I could then copy/paste super easy into an excel spreadsheet.

Step 1: Set up an API call in Postman that successfully returns the data you want to visualize.

In this case, I'm going to set up a call to the Permissions API to get a list of the permissions available in the dev environment.

I added a parameter of length=10000 because FOLIO's default parameter is 10, so it needs to be tons longer in order to get all the results back.

Step 2: Set up your visualization

This is the part I had the most trouble with because I am definitely not a programmer. But hopefully it can make sense. 

Go to the Tests tab in your API call.

This is your basic setup. You have a part at the beginning:

var template = ` `;

This is where you put in your code for the visualization you want to show up. It's essentially like extended HTML, and I'll write it out in the next part.

Then the code underneath that:

// Set visualizer pm.visualizer.set(template, { // Pass the response body parsed as JSON as `data` response: pm.response.json() });

is what spits out the visualization.

SO, because I want to make a table show up, I'm going to put code in that var section that looks a lot like HTML for making a table, that shows the 

 

var template = ` <table bgcolor="#FFFFFF"> <tr> <th>Display Name</th> <th>Permission Name</th> <th>Sub Permissions</th> <th>Child Of</th> </tr> {{#each response.permissions}} <tr> <td>{{displayName}}</td> <td>{{permissionName}}</td> <td>{{subPermissions}}</td> <td>{{childOf}}</td> </tr> {{/each}} </table> `;

So what I think is happening here is that you put in the table code, and the table headers just like you would expect. 

But for the table rows, you get to use this magic {{#each response.SOMETHING}} loop to format the JSON data

The excellent thing about this is that you can change the order of the JSON fields. So in this example, I have Display Name showing up first when in the JSON permission name shows up first.

Also, depending on the structure of the JSON, you would change the response.permissions part. So a JSON for a permission record on the top level doesn't have anything that I want to show up as nested. But, let's say I wanted that ChildOf field to be broken down into pieces, I think I'd have to do a loop with

{{#each response.permissions.childOf}} {{/each}}

to loop over the values in that field. But I may be wrong about this - I haven't really banged on it that deeply.

 

So to sum up, this is everything that is in the Tests tab:

The full content of the Tests Tab
var template = ` <table bgcolor="#FFFFFF"> <tr> <th>Display Name</th> <th>Permission Name</th> <th>Sub Permissions</th> <th>Child Of</th> </tr> {{#each response.permissions}} <tr> <td>{{displayName}}</td> <td>{{permissionName}}</td> <td>{{subPermissions}}</td> <td>{{childOf}}</td> </tr> {{/each}} </table> `; // Set visualizer pm.visualizer.set(template, { // Pass the response body parsed as JSON as `data` response: pm.response.json() });

 

Step 3: Test Your Visualization and View Your Output

 

So now you run your API!

 

 

To get to the Visualizer, scroll down to the Body section, and instead of clicking on Pretty or Raw to get the JSON, click Visualize.

Then to copy the output to Excel, click in the window, do a CTRL-A CTRL-C (select all and copy), and then in Excel, paste it as "match destination formatting." 

 

 

 

 

 

 

 

 

 

Comments