Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Opsgenie Alert API - 422 Sum of offset and limit should be lower than 20k

Isabel Giang January 11, 2021

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?

 

1 answer

1 accepted

3 votes
Answer accepted
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2021

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.

Nick H
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 14, 2021

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

Like Steffen Opel _Utoolity_ likes this
Bin Liang
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 18, 2023

@Nick HWhat 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?

Nick H
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 18, 2023

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)
Bin Liang
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 18, 2023

@Nick HHow 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?

Nick H
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 18, 2023

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

query.jpg

Bin Liang
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 19, 2023

@Nick HThe 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

Nick H
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 19, 2023

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events