When I developed a forge app against large dataset, the Rest API call to get all sprints will trigger rate limit. I want to get the latest 20 sprints, instead of all sprints. Any Atlassian developers can take a look? Thanks.
Get Sprints API need to sort by Sprint Id so that I can just fetch the latest N sprints, but not all
The Get a sprint endpoint returns only the sprints you ask for, not all sprints:
Get sprint
GET /rest/agile/1.0/sprint/{sprintId}
Returns the sprint for a given sprint ID.
Are you sure you’re not confusing it with the Get all sprints endpoint?
Also, what do you mean by ‘latest’ sprint? Sprints can have only one of three possible states…future, active or closed. Searching for sprints based on their states is already supported by the Get all sprints endpoint via the state parameter:
state
object
Filters results to sprints in specified states. Valid values: future, active, closed. You can define multiple states separated by commas, e.g. state=active,closed
sorry for the typo and the correct one is: https://developer.atlassian.com/cloud/jira/software/rest/api-group-board/#api-rest-agile-1-0-board-boardid-sprint-get
What I want is to fetch the latest 20 sprints using API (latest means the sprints ordered by sprint id desc)
As you can see from reading the documentation for the Get all sprints endpoint, it doesn’t have any functionality to limit or sort the search results based on your specific requirements, so you will have to do that in your app’s code.
I suggest that you start by making the decision as to whether you want to get only the sprints with the status future or active as being the ‘latest’, or whether you want only the closed sprints, then at least the set returned will be a bit smaller instead of getting them all, which leaves only the coding task of sorting the sprints by their ID and discarding all but the last 20.
Also, I think you have missed an important concept, which is that the ID of a sprint is just a unique, sequentially numbered identifier of the object that is assigned at the time of creation, but it has no correlation to the name of the sprint or the start date, which are the true indicators of it being the ‘latest’ based on ranking / ordering as viewed on a board.
Have fun with the problem.