# Import API

> 原文：[https://docs.gitlab.com/ee/api/import.html](https://docs.gitlab.com/ee/api/import.html)

*   [Import repository from GitHub](#import-repository-from-github)
*   [Import repository from Bitbucket Server](#import-repository-from-bitbucket-server)

# Import API[](#import-api "Permalink")

## Import repository from GitHub[](#import-repository-from-github "Permalink")

通过 API 将项目从 GitHub 导入到 GitLab.

```
POST /import/github 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `personal_access_token` | string | yes | GitHub 个人访问令牌 |
| `repo_id` | integer | yes | GitHub 存储库 ID |
| `new_name` | string | no | 新存储库名称 |
| `target_namespace` | string | yes | 要将存储库导入的命名空间 |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "personal_access_token=abc123&repo_id=12345&target_namespace=root" "https://gitlab.example.com/api/v4/import/github" 
```

响应示例：

```
{  "id":  27,  "name":  "my-repo",  "full_path":  "/root/my-repo",  "full_name":  "Administrator / my-repo"  } 
```

## Import repository from Bitbucket Server[](#import-repository-from-bitbucket-server "Permalink")

通过 API 将项目从 Bitbucket Server 导入到 GitLab.

**注意：** Bitbucket 项目密钥仅用于在 Bitbucket 中查找存储库. 如果要将存储库导入到 GitLab 组，则必须指定`target_namespace` . 如果您未指定`target_namespace` ，则项目将导入您的个人用户名称空间.

```
POST /import/bitbucket_server 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `bitbucket_server_url` | string | yes | Bitbucket 服务器网址 |
| `bitbucket_server_username` | string | yes | Bitbucket 服务器用户名 |
| `personal_access_token` | string | yes | Bitbucket 服务器个人访问令牌/密码 |
| `bitbucket_server_project` | string | yes | Bitbucket 项目密钥 |
| `bitbucket_server_repo` | string | yes | Bitbucket 存储库名称 |
| `new_name` | string | no | 新的回购名称 |
| `target_namespace` | string | no | 导入仓库的命名空间 |

```
curl --request POST \
  --url https://gitlab.example.com/api/v4/import/bitbucket_server \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" \
  --data '{
    "bitbucket_server_url": "http://bitbucket.example.com",
    "bitbucket_server_username": "root",
    "personal_access_token": "Nzk4MDcxODY4MDAyOiP8y410zF3tGAyLnHRv/E0+3xYs",
    "bitbucket_server_project": "NEW",
    "bitbucket_server_repo": "my-repo"
}' 
```