Opsgenie Alert API - 422 Sum of offset and limit should be lower than 20k
Asked by Isabel Giang:

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?


Answers:
author: David Bakkers
body: 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](https://docs.opsgenie.com/docs/api-rate-limiting), 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](https://docs.opsgenie.com/docs/alerts-search-query-help) 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.

comments: author: Nick H
body: Hi [@Isabel Giang](/t5/user/viewprofilepage/user-id/4219188) ,

The limit it set to a hard 20k, and cannot be increased. So we see customers breaking the search into batches like [@David Bakkers](/t5/user/viewprofilepage/user-id/1575730) 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


author: Bin Liang
body: [@Nick H](/t5/user/viewprofilepage/user-id/2540930)What 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?


author: Nick H
body: Hi [@Bin Liang](/t5/user/viewprofilepage/user-id/2469702) ,

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)
```


author: Bin Liang
body: [@Nick H](/t5/user/viewprofilepage/user-id/2540930)How should the query with OR and parentheses in web querystring should be construed? such as [https://api.opsgenie.com/v2/alerts?limit=1999\&createdAt](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?


author: Nick H
body: I use a [URL encoder](https://www.urlencoder.org/) 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
> ```

![query.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/287009iCBC870674A120BC3/image-size/large?v=v2&px=999 "query.jpg")


author: Bin Liang
body: [@Nick H](/t5/user/viewprofilepage/user-id/2540930)The 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


author: Nick H
body: 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.


Tags: alert

rest-api