0

List email addresses for current user

by
Published Oct 24, 2023

Returns all the authenticated user's email addresses. Both confirmed and unconfirmed.

Script bitbucket Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List email addresses for current user
7
 * Returns all the authenticated user's email addresses. Both
8
confirmed and unconfirmed.
9
 */
10
export async function main(auth: Bitbucket) {
11
  const url = new URL(`https://api.bitbucket.org/2.0/user/emails`);
12

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