0
Update a user application property
One script reply has been approved by the moderators Verified

Update an application property value stored against a user.

Created by hugo697 394 days ago Viewed 9001 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 394 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Update a user application property
7
 * Update an application property value stored against a user.
8
 */
9
export async function main(
10
  auth: Bitbucket,
11
  selected_user: string,
12
  app_key: string,
13
  property_name: string,
14
  body: { _attributes?: ("public" | "read_only")[]; [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://api.bitbucket.org/2.0/users/${selected_user}/properties/${app_key}/${property_name}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "PUT",
22
    headers: {
23
      "Content-Type": "application/json",
24
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.text();
33
}
34