I need help to create script for test for REST API

{

    "count": 11,

    "name": "Chat Queue Statistics",

    "columnNames": [

        "Queue",

        "Snapshot: Agents Online",

        "Snapshot: Agents Available",

        "Snapshot: Active Chats",

        "Snapshot: Available Chats",

        "Snapshot: Waiting Chats",

        "Snapshot: Max Wait (secs)",

        "Snapshot: Avg. Wait (secs)",

        "Cumulative: Avg. Handle Time (AHT) (secs)",

        "Cumulative: Avg. Message Response Time (secs)",

        "Cumulative: Chats Entered",

        "Cumulative: Chats Exited",

        "Cumulative: Chats Completed",

        "Cumulative: % Chats with no Agent Interaction",

        "Cumulative: SLAs Met (%)",

        "Last Recorded Activity"
    ] 
} 

I want to acces Active chats and Max. wait time

@kaurraman275:

Please check if the below code is helpful for you :slight_smile:

var resp = JSON.parse(responseBody);

//console.log(resp.columnNames);

for (var i = 0;i<resp.columnNames.length;i++) {

console.log("Index Value is " + i);

//checking column names

if (resp.columnNames[i] == ‘Snapshot: Active Chats’){

pm.test(“Snapshot: Active Chats”, function(){

        pm.expect(resp.columnNames[i]).to.eql('Snapshot: Active Chats');

})

}

else if (resp.columnNames[i] == ‘Snapshot: Max Wait (secs)’){

pm.test(“Snapshot: Max Wait (secs)”, function(){

        pm.expect(resp.columnNames[i]).to.eql('Snapshot: Max Wait (secs)');

})

}}

It is giving me index numbers only but i need to see how many chats are active and what is Max. wait.How can i do that.

That information is not part of that response body - the array is a list of column names.

Where are you seeing the data for each of those columns?

{

"count": 5,

"name": "Chat Queue Statistics",

"columnNames": [

    "Queue",

    "Snapshot: Agents Online",

    "Snapshot: Agents Available",

    "Snapshot: Active Chats",

    "Snapshot: Available Chats",

    "Snapshot: Waiting Chats",

    "Snapshot: Max Wait (secs)",

    "Snapshot: Avg. Wait (secs)",

    "Cumulative: Avg. Handle Time (AHT) (secs)",

    "Cumulative: Avg. Message Response Time (secs)",

    "Cumulative: Chats Entered",

    "Cumulative: Chats Exited",

    "Cumulative: Chats Completed",

    "Cumulative: % Chats with no Agent Interaction",

    "Cumulative: SLAs Met (%)",

    "Last Recorded Activity"

],

"rows": [

    [

        "Default Chat Queue",

        "1",

        "0",

        "0",

        "0",

        "0",

        "0",

        "0",

        null,

        null,

        "0",

        "0",

        "0",

        null,

        "0.000000",

        "'2020-09-05 21:44:27'"

    ],

    [

        "Support_Chat_E",

        "1",

        "0",

        "0",

        "0",

        "0",

        "0",

        "0",

        "913.090909",

        "69.202703",

        "10",

        "11",

        "11",

        "0.000000",

        "0.454545",

        "'2020-09-05 21:19:20'"

    ],

    [

        "Support_Chat_F",

        "1",

        "0",

        "0",

        "0",

        "0",

        "0",

        "0",

        null,

        null,

        "0",

        "0",

        "0",

        null,

        "0.000000",

        "'2020-09-05 21:19:20'"

    ],

    [

        "Track_Chat_E",

        "1",

        "0",

        "0",

        "0",

        "0",

        "0",

        "0",

        "746.581395",

        "74.179688",

        "34",

        "47",

        "43",

        "0.117647",

        "0.325581",

        "'2020-09-05 21:19:20'"

    ],

    [

        "Track_Chat_F",

        "1",

        "0",

        "0",

        "0",

        "0",

        "0",

        "0",

        null,

        null,

        "0",

        "0",

        "0",

        null,

        "0.000000",

        "'2020-09-05 21:19:20'"

    ]

its under rows and different queue names are there .For example Default queue statistics.

If you column names are going to be static, we can just loop the rows to reach the elements. Else we need to have loop to pick the column names as well. Considering the column names are static, I have iterated the rows values and tried to print everything in console.

var resp = JSON.parse(responseBody);

console.log(resp.rows.length);

for (var j = 0;j<resp.rows.length;j++){

//console.log("Index Value is " + i);

//console.log("Index Value is " + j);

console.log("Queue Name is " + resp.rows[j][0]);

console.log("Snapshot: Agents Online is " + resp.rows[j][1]);

console.log("Snapshot: Agents Available " + resp.rows[j][2]);

console.log("Snapshot: Active Chats " + resp.rows[j][3]);

console.log("Snapshot: Available Chats " + resp.rows[j][4]);

console.log("Snapshot: Waiting Chats " + resp.rows[j][5]);

console.log("Snapshot: Max Wait (secs) " + resp.rows[j][6]);

console.log("Snapshot: Avg. Wait (secs) " + resp.rows[j][7]);

console.log("Cumulative: Avg. Handle Time (AHT) (secs) " + resp.rows[j][8]);

console.log("Cumulative: Avg. Message Response Time (secs) " + resp.rows[j][9]);

console.log("Cumulative: Chats Entered " + resp.rows[j][10]);

console.log("Cumulative: Chats Exited " + resp.rows[j][11]);

console.log("Cumulative: Chats Completed " + resp.rows[j][12]);

console.log("Cumulative: % Chats with no Agent Interaction " + resp.rows[j][13]);

console.log("Cumulative: SLAs Met (%) " + resp.rows[j][14]);

console.log("Last Recorded Activity " + resp.rows[j][15]);

}

What I would do…
I will use visualization build in Postman. But this require some JS fun to rearrange the response… because from list of lists you cannot build working template… I have tried. But if someone have achieve to build template from data in list of elements instead of aka Json Dictionary.
Then you can with CSS styles format those with wait time longer than XYZ and overall counter on top of the table with active number of rooms.

Rearrange of data is the most tricky part as your keys - ColumnName and values lists of lists are separated … I assume this is for data bandwidth optimization

Thank you for your reply. I would like to have more information of this as i am trying to create monitor.Please help me to create CSS style that you just mentioned.

The CSS is the cherry on top…
Step no.0 is to rearrange response to sth like. But be advised this is not valid Json. Keys should not contains white chars so you need to simplify them

[
"rows":[
  { 
    "Queue": "Default Chat Queue",
    "Snapshot: Agents Online":         "1",
    "Snapshot: Agents Available":         "0",
    "Snapshot: Active Chats":         "0",
    "Snapshot: Available Chats":         "0",
    "Snapshot: Waiting Chats":         "0",
    "Snapshot: Max Wait (secs)":         "0",
    "Snapshot: Avg. Wait (secs)":         "0",
    "Cumulative: Avg. Handle Time (AHT) (secs)":         null,
    "Cumulative: Avg. Message Response Time (secs)":         null,
    "Cumulative: Chats Entered":         "0",
    "Cumulative: Chats Exited":         "0",
    "Cumulative: Chats Completed":         "0",
    "Cumulative: % Chats with no Agent Interaction":         null,
    "Cumulative: SLAs Met (%)":         "0.000000",	
    "Last Recorded Activity":        "'2020-09-05 21:44:27'"
},
//another room
]

Then you need to create the template. Some basic HTML table - tr, td… etc … after you manage to display it adding style will be easy with inline javascript line.

here you have some basic template, but more work should be done to display data

const vizData = {
    "rows" : rows,
    "columnNames": columnNames
}

var template = `
    <style type="text/css">
    html { background: #fff; }
        .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>
    <table class="tftable" border="1">
        <tr>
        {{#each columnNames}}
            <th id={{@key}}>{{@value}}</th>
            <div style="display: none;"> or all of the column names manually added if they are static.</div>
        {{/each}}
        </tr>
        
        {{#each rows}}
         <tr id=row_{{@key}} onClick="handleClick(this.id)">
            <td id={{@key}}>{{Queue}}</td>        
            <td id={{@key}}>{{SnapshotAgentsOnline}}</td>                   
            <div style="display: none;"> // and all others </div> 
        </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, vizData);

dictionary vizData need to be populated with right Json inputs.

and … then you can add those CSS for rooms with some property bigger than XYZ … But JavaScipt, HTML and CSS skills are sth to learn from some other site.

After next 30min I have done the template … and JavaScript to rearrange data is not necessary with those tweaks to template… some advanced built in tags like #this which are skipped in official docs or does not have enough ‘spot lights’ .

const res  =  pm.response.json()
const vizData = {
    "rows" : res.rows,
    "columnNames": res.columnNames
}

var template = `
    <style type="text/css">
    html { background: #fff; }
        .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>
    <table class="tftable" border="1">
        <tr>        
        {{#each columnNames}}            
            <th>{{this}}</th>            
        {{/each}}
        </tr>
        
        {{#each rows}}
         <tr id=row_{{@key}} onClick="handleClick(this.id)">
                {{#each this}}
                    <td>{{this}}</td>
                {{/each}}
        </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, vizData);

This may be enough for you
If not the CSS part I gona leave for you :slight_smile: have fun

I am unable to see output as you mentioned in your reply.

i am trying to run both html templates in my script.Please help

Syntax Error is quite descriptive.
Post here your Tests page with the response as a screen so It will be easier to catch issues.

i am looking to set threshold as when Active chats are 0 and Max wait time time is more than 5 min i should get alert .I need help with that issue.

i am looking to create thresholds as i mentioned in last reply.Please help.I am looking to create alert.for these thresholds.