0

Get Board

by
Published today

Get a Jira Software board by ID, including its type and the project it belongs to.

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
 * Get Board
29
 * Get a Jira Software board by ID, including its type and the project it belongs to.
30
 */
31
export async function main(auth: RT.Jira, board_id: DynSelect_board_id) {
32
  const url = new URL(
33
    `https://${auth.domain}.atlassian.net/rest/agile/1.0/board/${board_id}`
34
  )
35

36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
40
      Accept: "application/json",
41
    },
42
  })
43

44
  if (!response.ok) {
45
    throw new Error(`${response.status} ${await response.text()}`)
46
  }
47

48
  return await response.json()
49
}
50