0
List variables for a user
One script reply has been approved by the moderators Verified

Find user level variables. This endpoint has been deprecated, and you should use the new workspaces endpoint. For more information, see the announcement.

Created by hugo697 418 days ago Viewed 9009 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 418 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List variables for a user
7
 * Find user level variables.
8
This endpoint has been deprecated, and you should use the new workspaces endpoint. For more information, see [the announcement](https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-teams-deprecation/).
9
 */
10
export async function main(auth: Bitbucket, selected_user: string) {
11
  const url = new URL(
12
    `https://api.bitbucket.org/2.0/users/${selected_user}/pipelines_config/variables`
13
  );
14

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