Get user membership for a workspace

Returns the workspace membership, which includes a `User` object for the member and a `Workspace` object for the requested workspace.

Script bitbucket Verified

by hugo697 ยท 10/24/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 375 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get user membership for a workspace
7
 * Returns the workspace membership, which includes
8
a `User` object for the member and a `Workspace` object
9
for the requested workspace.
10
 */
11
export async function main(auth: Bitbucket, member: string, workspace: string) {
12
  const url = new URL(
13
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/members/${member}`
14
  );
15

16
  const response = await fetch(url, {
17
    method: "GET",
18
    headers: {
19
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29