0
Get a linker value
One script reply has been approved by the moderators Verified

Get a single linker value of the authenticated application.

Created by hugo697 197 days ago Viewed 5863 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 197 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get a linker value
7
 * Get a single linker value
8
of the authenticated application.
9
 */
10
export async function main(
11
  auth: Bitbucket,
12
  linker_key: string,
13
  value_id: string
14
) {
15
  const url = new URL(
16
    `https://api.bitbucket.org/2.0/addon/linkers/${linker_key}/values/${value_id}`
17
  );
18

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