0

Delete an explicit user permission for a repository

by
Published Oct 24, 2023

Deletes the repository user permission between the requested repository and user, if one exists. Only users with admin permission for the repository may access this resource. The only authentication method for this endpoint is via app passwords.

Script bitbucket Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Delete an explicit user permission for a repository
7
 * Deletes the repository user permission between the requested repository and user, if one exists.
8

9
Only users with admin permission for the repository may access this resource.
10

11
The only authentication method for this endpoint is via app passwords.
12
 */
13
export async function main(
14
  auth: Bitbucket,
15
  repo_slug: string,
16
  selected_user_id: string,
17
  workspace: string
18
) {
19
  const url = new URL(
20
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/permissions-config/users/${selected_user_id}`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "DELETE",
25
    headers: {
26
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.text();
35
}
36