Hello. I'm trying to use Opsgenie's Alerts REST API to pull alerts from the past few months.
I have been using limit = 100 to paginate the API responses.
Once I react limit = 20000, I'm unable to query any more, getting a 422 error code and the message "Sum of offset and limit should be lower than 20k."
Is there a reason why this is happening and is there some way to get more than 20000 alerts?
Do you still get the error when you submit a request with offset=19999 and you don't set the limit? If so, I would say you've reached a physical limit set by Atlassian.
It's not a rate limit, but a record count limit, so it might be something that can be increased in alignment with your account type. Maybe contact their sales department?
If that limit can't be increased, then you may have to break your searching down into batches based on another criteria. Use the query parameter to specify a filter for the alerts to find and, say, find all the alerts in that time range that were for a particular team, then do a series of searches in the same range for the other teams.
Hi @Isabel Giang ,
The limit it set to a hard 20k, and cannot be increased. So we see customers breaking the search into batches like @David Bakkers mentioned.
Most of the time we'll see customers using the date/time range for this. If you wanted to query alerts throughout 2020, you'd want something like:
createdAt>31-12-2019 AND createdAt<01-01-2021
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nick HallerWhat is the syntax for filter by Priority and createdAt in the query (priority=P1 or priority=p2) AND createdAt>31-12-2022 AND createdAt<10-12-2023?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bin Liang ,
That query should work, and will pull P1 and P2 alerts created between Jan 1, 2023 - Dec 9, 2023.
The < > signs do not pull for the day of. If you needed those as well, you'd want to use:
createdAt>=31-12-2022 AND createdAt<=10-12-2023 AND (priority=P1 OR priority=p2)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nick HallerHow should the query with OR and parentheses in web querystring should be construed? such as https://api.opsgenie.com/v2/alerts?limit=1999&createdAt>=31-12-2022&createdAt<=10-12-2023&priority=P1ORpriority=P2
I know the querystring has a bad syntax. What is the correct one? Thanks!
Also, how can I get more than 100 rows?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use a URL encoder to determine what the query should be, so it'd be something like this to copy/paste in your browser:
https://customer_name.app.opsgenie.com/alert/list?query=createdAt%3E31-12-2022%20AND%20createdAt%3C10-12-2023%20AND%20%28priority%3DP1%20OR%20priority%3Dp2%29
Or something like this to use in an API tool such as Postman:
https://api.opsgenie.com/v2/alerts?query=createdAt%3E31-12-2022%20AND%20createdAt%3C10-12-2023%20AND%20%28priority%3DP1%20OR%20priority%3Dp2%29
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nick HallerThe html-encoded querystring works great. Thanks!!
But I set the limit=1999 but it was ignored. I got100 rows only, a week or so data. I hope I do not need to append data 50 times to get annual data. Please help!
Bin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The limit is 100 at this time. If you need to pull more than 100 alerts then your best option would be to run this query in the UI, and export the list of alerts after.
Or run a report in the Analytics tab and export the data there.
Otherwise you'd need to customize some script that runs through the first 100, next 100, etc. to automate this via API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.