0

Check issue export status

by
Published Oct 24, 2023

This endpoint is used to poll for the progress of an issue export job and return the zip file after the job is complete.

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
 * Check issue export status
7
 * This endpoint is used to poll for the progress of an issue export
8
job and return the zip file after the job is complete.
9
 */
10
export async function main(
11
  auth: Bitbucket,
12
  repo_name: string,
13
  repo_slug: string,
14
  task_id: string,
15
  workspace: string
16
) {
17
  const url = new URL(
18
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/export/${repo_name}-issues-${task_id}.zip`
19
  );
20

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