0

List Board Issues

by
Published today

List the issues on a board, optionally narrowed by a JQL query. Paginated with `start_at` / `max_results`.

Script jira Verified

The script

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

3
async function get(auth: RT.Jira, path: string) {
4
  const response = await fetch(`https://${auth.domain}.atlassian.net${path}`, {
5
    headers: {
6
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
7
      Accept: "application/json",
8
    },
9
  })
10
  if (!response.ok) {
11
    throw new Error(`${response.status} ${await response.text()}`)
12
  }
13
  return await response.json()
14
}
15

16
export type DynSelect_board_id = string
17

18
// Resolver: the site's boards (first 50).
19
export async function board_id(auth: RT.Jira) {
20
  const { values } = await get(auth, "/rest/agile/1.0/board?maxResults=50")
21
  return values.map((b: { id: number; name: string; type: string }) => ({
22
    value: String(b.id),
23
    label: `${b.name} (${b.type})`,
24
  }))
25
}
26

27
/**
28
 * List Board Issues
29
 * List the issues on a board, optionally narrowed by a JQL query. Paginated with `start_at` / `max_results`.
30
 */
31
export async function main(
32
  auth: RT.Jira,
33
  board_id: DynSelect_board_id,
34
  jql: string | undefined,
35
  fields: string[] | undefined,
36
  expand: string | undefined,
37
  start_at: number | undefined,
38
  max_results: number | undefined
39
) {
40
  const url = new URL(
41
    `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}/issue`
42
  )
43
  if (jql != null && jql !== "") {
44
    url.searchParams.append("jql", jql)
45
  }
46
  if (fields?.length) {
47
    url.searchParams.append("fields", fields.join(","))
48
  }
49
  if (expand != null && expand !== "") {
50
    url.searchParams.append("expand", expand)
51
  }
52
  if (start_at != null) {
53
    url.searchParams.append("startAt", String(start_at))
54
  }
55
  if (max_results != null) {
56
    url.searchParams.append("maxResults", String(max_results))
57
  }
58

59
  const response = await fetch(url, {
60
    method: "GET",
61
    headers: {
62
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
63
      Accept: "application/json",
64
    },
65
  })
66

67
  if (!response.ok) {
68
    throw new Error(`${response.status} ${await response.text()}`)
69
  }
70

71
  return await response.json()
72
}
73