Get an email address for current user

Returns details about a specific one of the authenticated user's email addresses. Details describe whether the address has been confirmed by the user and whether it is the user's primary address or not.

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 an email address for current user
7
 * Returns details about a specific one of the authenticated user's
8
email addresses.
9

10
Details describe whether the address has been confirmed by the user and
11
whether it is the user's primary address or not.
12
 */
13
export async function main(auth: Bitbucket, email: string) {
14
  const url = new URL(`https://api.bitbucket.org/2.0/user/emails/${email}`);
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