0
Export issues
One script reply has been approved by the moderators Verified

A POST request to this endpoint initiates a new background celery task that archives the repo's issues.

When the job has been accepted, it will return a 202 (Accepted) along with a unique url to this job in the 'Location' response header. This url is the endpoint for where the user can obtain their zip files."

Created by hugo697 394 days ago Viewed 9019 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 394 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Export issues
7
 * A POST request to this endpoint initiates a new background celery task that archives the repo's issues.
8

9
When the job has been accepted, it will return a 202 (Accepted) along with a unique url to this job in the
10
'Location' response header. This url is the endpoint for where the user can obtain their zip files."
11
 */
12
export async function main(
13
  auth: Bitbucket,
14
  repo_slug: string,
15
  workspace: string,
16
  body: {
17
    type: string;
18
    project_key?: string;
19
    project_name?: string;
20
    send_email?: boolean;
21
    include_attachments?: boolean;
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/export`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.text();
42
}
43