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

A POST request to this endpoint will import the zip file given by the archive parameter into the repository. All existing issues will be deleted and replaced by the contents of the imported zip file.

Imports are done through a multipart/form-data POST. There is one valid and required form field, with the name "archive," which needs to be a file field:

$ curl -u  -X POST -F archive=@/path/to/file.zip https://api.bitbucket.org/2.0/repositories///issues/import
Created by hugo697 174 days ago Viewed 3736 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 174 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Import issues
7
 * A POST request to this endpoint will import the zip file given by the archive parameter into the repository. All
8
existing issues will be deleted and replaced by the contents of the imported zip file.
9

10
Imports are done through a multipart/form-data POST. There is one valid and required form field, with the name
11
"archive," which needs to be a file field:
12

13
```
14
$ curl -u  -X POST -F archive=@/path/to/file.zip https://api.bitbucket.org/2.0/repositories///issues/import
15
```
16
 */
17
export async function main(
18
  auth: Bitbucket,
19
  repo_slug: string,
20
  workspace: string
21
) {
22
  const url = new URL(
23
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/import`
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39