Delete user property

Deletes a property from 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 delete a property from any user. * Access to Jira, to delete a property from the calling user's record.

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
 * Delete user property
8
 * Deletes a property from 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 delete a property from any user.
15
 *  Access to Jira, to delete a property from the calling user's record.
16
 */
17
export async function main(
18
  auth: Jira,
19
  propertyKey: string,
20
  accountId: string | undefined,
21
  userKey: string | undefined,
22
  username: string | undefined
23
) {
24
  const url = new URL(
25
    `https://${auth.domain}.atlassian.net/rest/api/2/user/properties/${propertyKey}`
26
  );
27
  for (const [k, v] of [
28
    ["accountId", accountId],
29
    ["userKey", userKey],
30
    ["username", username],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "DELETE",
38
    headers: {
39
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.text();
48
}
49