Get user property keys

Returns the keys of all properties for a user. Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to access the property keys on any user. * Access to Jira, to access the calling user's property keys.

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
 * Get user property keys
8
 * Returns the keys of all properties for a user.
9

10
Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira.
11

12
**[Permissions](#permissions) required:**
13

14
 *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to access the property keys on any user.
15
 *  Access to Jira, to access the calling user's property keys.
16
 */
17
export async function main(
18
  auth: Jira,
19
  accountId: string | undefined,
20
  userKey: string | undefined,
21
  username: string | undefined
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/user/properties`
25
  );
26
  for (const [k, v] of [
27
    ["accountId", accountId],
28
    ["userKey", userKey],
29
    ["username", username],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48