Making REST call pagination wise to retrieve records

Mason5
Mega Expert

Hi All,

How can we create outbound REST web-service to allow third party app, to retrieve only specific set of records(like 10 records) and at 3rd party side when user hit Next, then provide/send next 10 records? is it possible to achieve?

 

Many thanks in Advance 

1 ACCEPTED SOLUTION

Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi Mason,

There are two ways of achieving this
1. In first approach, third party will have to change the parameter with incremented number

You can make use of the sysparm_offset and sysparm_limit parameters.
For example: If you want to retrieve 10 records (sysparm_limit=10) in the record set starting from the beginning (sysparm_offset=0) of the record set.

/api/now/table/<tablename>?sysparm_limit=10&sysparm_offset=0


Then for next 10 records, you would simply increment the value of sysparm_offset by the value of your sysparm_limit

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=10

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=20

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=30

.

.

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=n


2. Create a Scriptted rest API and on each call you can store the record set in a log table and send only those records those are not avaible in the log table.

Hope this helps!


Regards,
Ujjawal

View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hello,

The third party need to send additional parameters to limit the result set and this could be achieved by sending the sysparm_limit & sysparm_offset in the endpoint URL.

Thanks

For example the following will retrieve 5 records (sysparm_limit=5) in the record set starting from the beginning (sysparm_offset=0) of the record set.

/api/now/v1/table/incident?sysparm_limit=5&sysparm_offset=0&sysparm_query=active=true

 

The get the next 5 records, you would simply increment the value of sysparm_offset by the value of your sysparm_limit

 

/api/now/v1/table/incident?sysparm_limit=5&sysparm_offset=5&sysparm_query=active=true

 

You will also get a URL in the response Header that provides a link to first,prev,next and last pages based on values used for sysparm_offset and sysparm_limit. You can also make use of this link if required.

Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi Mason,

There are two ways of achieving this
1. In first approach, third party will have to change the parameter with incremented number

You can make use of the sysparm_offset and sysparm_limit parameters.
For example: If you want to retrieve 10 records (sysparm_limit=10) in the record set starting from the beginning (sysparm_offset=0) of the record set.

/api/now/table/<tablename>?sysparm_limit=10&sysparm_offset=0


Then for next 10 records, you would simply increment the value of sysparm_offset by the value of your sysparm_limit

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=10

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=20

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=30

.

.

/api/now/table/tablename?sysparm_limit=10&sysparm_offset=n


2. Create a Scriptted rest API and on each call you can store the record set in a log table and send only those records those are not avaible in the log table.

Hope this helps!


Regards,
Ujjawal

Hi Ujjawal,

Can you guide me with scripted API syntax that was mentioned in 2)

 

Thanks

Sailesh