Pagination loop scripting for the rest message to retrieve all the data.

Yogita11_
Tera Contributor
I completed the integration with Tenable, and the issue I am experiencing is pagination. So the scenario is that it has a limit of 300 records, so the first call sends 300 records, but we need to do a loop to return all of them.
In this case, I'll explain how the offset works. We have 359 records in the tenable, so the first call returns 300 records, and the next call, if I set 300 as  a offset, it sends the remaining 59 records. So, for this, we need to create logic in which the offset is set based on the number of returned records, which I can able to calculate from the for loop.
gs.info(j) will print 300.
So, can anyone help me build the logic here?
Thanks in advance.



 var rest_message = new sn_ws.RESTMessageV2('Tenable', 'devices');
    //rest_message.setStringParameterNoEscape('offset', '');
    var response = rest_message.execute();
    var responseBody = response.getBody();
    var parsedResponse = JSON.parse(responseBody);

    for (var j = 0; j < parsedResponse.length; j++) {
        var serial = parsedResponse[j].serial_number;
        var grComputer = new GlideRecord('cmdb_ci_computer');
        grComputer.addEncodedQuery('serial_number=' + serial);
        grComputer.query();
        if (grComputer.next()) {
           // updating the records
        }
        gs.info('returned records count is'+ j);
    }
0 REPLIES 0