Step 2: Retrieve data

Suppose we want to display total number of issues in active sprint versus number of issues completed in the sprint. By examining Jira Software REST API, we find "Get issues for board" GET /rest/agile/1.0/board/{boardId}/issue: Returns all issues from a board, for a given board Id.

So, it returns all issues for the board and we want only issues that belong to an active sprint. Luckily the method has "jql" parameter, by passing which, we can apply additional JQL filtering. JQL function is to get issues belonging to active sprints: sprint in openSprints () and additionally to get issues that are completed: status in (Done). Please make sure to put here status or comma separated statuses that are appropriate for your workflow and match "completed" columns of the board. The board id can be extracted from the URL shown in your browser address bar when you select the board: https://brizoit.atlassian.net/secure/RapidBoard.jspa?rapidView=6.

So, finally we have 2 calls:

  • To retrieve all issues from the active sprint: /rest/agile/1.0/board/6/issue?jql=sprint%20in%20openSprints()&fields=id
  • To retrieve completed issues: /rest/agile/1.0/board/6/issue?jql=sprint%20in%20openSprints()%20and%20status%20in(Done)&fields=id

Please note that instead of spaces we have %20 which is encoded representation of the space character. Also we pass additional fields=id to indicate that we do not want any additional issue fields and by doing this we make the rest response smaller in size. Each of the calls returns JSON like:
 

{
  "expand": "names, schema",
  "startAt": 0,
  "maxResults": 50,
  "total": 1,
  "issues": [
    {
      "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
      "id": "21101",
      "self": "https://vkrupach.atlassian.net/rest/agile/1.0/issue/21101",
      "key": "TEST-7"
    }
  ]
}


Here we are interested only in number of issues so all we need is "total" attribute and we can ignore "issues" part and do not need to worry about paging.

Resources to check

When searching how to retrieve JIRA data that you want to display in your gadget, you should start from checking public REST APIs.