0

Count Issues Using JQL

by
Published today

Return the approximate number of issues matching a bounded JQL query, without fetching them.

Script jira Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Count Issues Using JQL
5
 * Return the approximate number of issues matching a bounded JQL query, without fetching them.
6
 */
7
export async function main(auth: RT.Jira, jql: string) {
8
  const url = new URL(
9
    `https://${auth.domain}.atlassian.net/rest/api/3/search/approximate-count`
10
  )
11

12
  const response = await fetch(url, {
13
    method: "POST",
14
    headers: {
15
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
16
      "Content-Type": "application/json",
17
      Accept: "application/json",
18
    },
19
    body: JSON.stringify({ jql }),
20
  })
21

22
  if (!response.ok) {
23
    throw new Error(`${response.status} ${await response.text()}`)
24
  }
25

26
  return await response.json()
27
}
28