Cursor pagination not working as expected in Data Stream

snehakarthi
Giga Contributor

Hi everyone,

I’m working on a Data Stream Action in ServiceNow to integrate with an external API that uses cursor-based pagination.

The API response looks like this:

JSON.png

 

I have configured Pagination setup:

 
 

Pagination1.pngPgination2.png

 

For the REST step, I am passing:

Restmessage1.png

 

 

Getting the below 400 error:

 

{"type":"about:blank","title":"Bad Request","status":400,"detail":"{\"errorId\":\"e7ab5292-10dd-49e3-8711-2252e8651be7\",\"error\":\"malformed_cursor\"}","instance":"/api/v1/users"}

 

If anyone faced this issue earlier, please help me.

 

Thanks!

 

 

 

 

2 REPLIES 2

tejarekanda
Tera Expert

Hi @snehakarthi ,
Can you Try the below script and try to verify in the logs that next cursor is coming properly.

(function paginate(variables, pageResponse) {

    var hasMore = pageResponse.paging.has_more;
    var nextCursor = pageResponse.paging.next_cursor;

    if (hasMore && nextCursor) {
        variables.getNextPage = true;
        variables.next_cursor = nextCursor;
    } else {
        variables.getNextPage = false;
        variables.next_cursor = null;
    }

    gs.info("Next Cursor: " + variables.next_cursor);

})(variables, pageResponse);

 

Hi @tejarekanda,

 

I'm still getting the below error:

 

{"type":"about:blank","title":"Bad Request","status":400,"detail":"{\"error\":\"malformed_cursor\",\"errorId\":\"4437a4b0-8d48-4a5f-bf2e-d455e6002a6b\"}","instance":"/api/v1/users"}

 

Thanks!