Limit results on REST API for pagination

Hey there,

is there any possibilty to limit my results on REST API calls? I need it for a pagination, so i have to set a limit and at least a starting point for the results.

So something like this:

<icinga2RestAPI>/v1/objects/services?start=199&limit=100

Thanks for your help.

Unfortunately the answer is no, there is no pagination in the Icinga 2 API. So you would need to handle pagination yourself, but as the result is basically an array this should be quite easy as long as Icinga 2 can handle your query and your program the result.

thank you for your answer. Okay, to build a pagination in frontend is easy but i have to reduce traffic, so it would be very useful to limit requests from icinga API. Otherwise i could buffer my call in a seperate API, which i have running for my backend, but that will be pretty complicated to do.
hmm… is there really no way?

If you have a specific sort order, you could limit with a filter utilizing the alphabet or so, but this will very likely not result in a good even pagination. But depending on the planned frontend it could be an option.

Depending on your environment using the database backend could be easier, but with IDO having its limits and IcingaDB only being a thing of the future, I am not sure about what I should recommend.

We have 1000s of API calls (maybe even 10s of thousands) every hour. We kept hitting a limit that would cause the API to not respond and trigger a watchdog to restart Icinga2. While this doesn’t help with pagination, increasing your memory on the Icinga2 master will help.

Of course, if your problem is for network traffic (and not reducing load on the API endpoint), this won’t help.

thank you for your reply, but i need to increase network traffic because we’re working with vSat and have less bandwidth offshore.

You might make a feature request on the repo (the API client is CPP), but I doubt it gets much attention short term.

Long term it might be nice to have the option to limit results.