How should I use cursor to fetch all possible entries using REST API?

Hello, I have some question regards the REST api for Confluence and how ‘route’ works.

Previously I was doing something like this in order to repeatedly call REST api until it reaches end of the page:

let address = `/wiki/api/v2/spaces/${spaceId}/properties?limit=250`;
  let propertyArray = [];
  while(true){
    const getProperties = await api.asApp().requestConfluence(route (address), {
      headers: {
        'Accept': 'application/json'
      }
    });
    const propertyReturn = await getProperties.json();

    propertyArray = propertyArray.concat(propertyReturn.results);
    if(propertyReturn._links.next == undefined || propertyReturn._links.next == null){ 
      break;
    }
    //set address to cursor
    address = propertyReturn._links.next;
  }

So basically, I had a variable that contains the REST API address, and I update it to cursor and call it again until there is no more cursor. However, recently, Atlassian team has update so that you can no longer do:

route (address)

For now, I just have a single REST API call, without having any address variable. I need a way to repeatedly call REST API until there is no more entries. Is there any idea about how to do this with current route changes?

If you know the route will be OK, you can use assumeTrustedRoute in place of route from @forge/api. Just make sure there’s no chance the route will include user input or anything.

1 Like

Thanks for the reply,

This worked for me, so I will set it as a solution.

Also, how did you find about this?

I ran into a similar problem a while ago. I think I got it from the documentation.