Can return enrollments- how to handle pagination?

Community Novice

This Node script is working well to return enrollments- but I am struggling with pagination.

const request = require('request');

let url = '[]=StudentEnrollment&state[... rel="next"';

request(url, function (err, response, body) {
console.log('error:', error);
} else {
let results = JSON.parse(body)

for (var i in results) {


the only way i know how to cycle through the pages is manually with page number in the URL, example: page=2, page=3, etc.

How can this be automated?

How can I design the script so it knows it's at the end? I assume an if-then structure that checks the state of rel. As long as it's "next," it keeps going, but what about when it's "last?"

Any help would be most appreciated. It's a rather urgent need. Thank you.

Labels (1)