Set user default columns

Sets the default [ issue table columns](https://confluence.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Set user default columns
8
 * Sets the default [ issue table columns](https://confluence.
9
 */
10
export async function main(
11
  auth: Jira,
12
  accountId: string | undefined,
13
  body: { columns?: string[] }
14
) {
15
  const url = new URL(
16
    `https://${auth.domain}.atlassian.net/rest/api/2/user/columns`
17
  );
18
  for (const [k, v] of [["accountId", accountId]]) {
19
    if (v !== undefined && v !== "") {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const formData = new FormData();
24
  for (const [k, v] of Object.entries(body)) {
25
    if (v !== undefined && v !== "") {
26
      formData.append(k, String(v));
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "PUT",
31
    headers: {
32
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
33
    },
34
    body: formData,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42