2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference, api
---
2018-03-27 19:54:05 +05:30
# Project import/export API
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41899) in GitLab 10.6.
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
See also:
- [Project import/export documentation ](../user/project/settings/import_export.md ).
2020-04-22 19:07:51 +05:30
- [Project import/export administration Rake tasks ](../administration/raketasks/project_import_export.md ). ** (CORE ONLY)**
2018-03-27 19:54:05 +05:30
## Schedule an export
Start a new export.
2020-03-13 15:44:24 +05:30
The endpoint also accepts an `upload` parameter. This parameter is a hash that contains
2018-05-09 12:01:36 +05:30
all the necessary information to upload the exported project to a web server or
to any S3-compatible platform. At the moment we only support binary
data file uploads to the final server.
2020-03-13 15:44:24 +05:30
From GitLab 10.7, the `upload[url]` parameter is required if the `upload` parameter is present.
2018-05-09 12:01:36 +05:30
2020-05-24 23:13:21 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
POST /projects/:id/export
```
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user |
2018-05-09 12:01:36 +05:30
| `description` | string | no | Overrides the project description |
| `upload` | hash | no | Hash that contains the information to upload the exported project to a web server |
| `upload[url]` | string | yes | The URL to upload the project |
| `upload[http_method]` | string | no | The HTTP method to upload the exported project. Only `PUT` and `POST` methods allowed. Default is `PUT` |
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/export" \
2018-11-18 11:00:15 +05:30
--data "upload[http_method]=PUT" \
--data-urlencode "upload[url]=https://example-bucket.s3.eu-west-3.amazonaws.com/backup?X-Amz-Algorithm=AWS4-HMAC-SHA256& X-Amz-Credential=AKIAIMBJHN2O62W8IELQ%2F20180312%2Feu-west-3%2Fs3%2Faws4_request& X-Amz-Date=20180312T110328Z& X-Amz-Expires=900& X-Amz-SignedHeaders=host& X-Amz-Signature=8413facb20ff33a49a147a0b4abcff4c8487cc33ee1f7e450c46e8f695569dbd"
2018-03-27 19:54:05 +05:30
```
```json
{
"message": "202 Accepted"
}
```
2021-02-22 17:27:13 +05:30
NOTE:
2020-05-24 23:13:21 +05:30
The upload request will be sent with `Content-Type: application/gzip` header. Ensure that your pre-signed URL includes this as part of the signature.
2018-03-27 19:54:05 +05:30
## Export status
Get the status of export.
2020-05-24 23:13:21 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /projects/:id/export
```
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user |
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/export"
2018-03-27 19:54:05 +05:30
```
2020-03-13 15:44:24 +05:30
Status can be one of:
- `none`
2020-04-08 14:13:33 +05:30
- `queued`
2020-03-13 15:44:24 +05:30
- `started`
- `finished`
2020-04-08 14:13:33 +05:30
- `regeneration_in_progress`
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
`queued` state represents the request for export is received, and is currently in the queue to be processed.
The `started` state represents that the export process has started and is currently in progress.
It includes the process of exporting, actions performed on the resultant file such as sending
an email notifying the user to download the file, uploading the exported file to a web server, etc.
`finished` state is after the export process has completed and the user has been notified.
`regeneration_in_progress` is when an export file is available to download, and a request to generate a new export is in process.
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
`none` is when there are no exports _queued_ , _started_ , _finished_ , or _being regenerated_
2018-03-27 19:54:05 +05:30
`_links` are only present when export has finished.
2020-11-24 15:15:51 +05:30
`created_at` is the project create timestamp, not the export start time.
2018-03-27 19:54:05 +05:30
```json
{
"id": 1,
"description": "Itaque perspiciatis minima aspernatur corporis consequatur.",
"name": "Gitlab Test",
"name_with_namespace": "Gitlab Org / Gitlab Test",
"path": "gitlab-test",
"path_with_namespace": "gitlab-org/gitlab-test",
"created_at": "2017-08-29T04:36:44.383Z",
"export_status": "finished",
"_links": {
"api_url": "https://gitlab.example.com/api/v4/projects/1/export/download",
"web_url": "https://gitlab.example.com/gitlab-org/gitlab-test/download_export",
}
}
```
## Export download
Download the finished export.
2020-05-24 23:13:21 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /projects/:id/export/download
```
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user |
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " --remote-header-name --remote-name "https://gitlab.example.com/api/v4/projects/5/export/download"
2018-03-27 19:54:05 +05:30
```
2020-03-13 15:44:24 +05:30
```shell
2018-03-27 19:54:05 +05:30
ls *export.tar.gz
2017-12-05_22-11-148_namespace_project_export.tar.gz
```
## Import a file
2020-05-24 23:13:21 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
POST /projects/import
```
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- |
| `namespace` | integer/string | no | The ID or path of the namespace that the project will be imported to. Defaults to the current user's namespace |
2019-12-21 20:55:43 +05:30
| `name` | string | no | The name of the project to be imported. Defaults to the path of the project if not provided |
2018-03-27 19:54:05 +05:30
| `file` | string | yes | The file to be uploaded |
| `path` | string | yes | Name and path for new project |
2018-05-09 12:01:36 +05:30
| `overwrite` | boolean | no | If there is a project with the same path the import will overwrite it. Default to false |
2018-10-15 14:42:47 +05:30
| `override_params` | Hash | no | Supports all fields defined in the [Project API ](projects.md ) |
2018-05-09 12:01:36 +05:30
2020-04-22 19:07:51 +05:30
The override parameters passed will take precedence over all values defined inside the export file.
2018-03-27 19:54:05 +05:30
2018-10-15 14:42:47 +05:30
To upload a file from your file system, use the `--form` argument. This causes
2018-03-27 19:54:05 +05:30
cURL to post data using the header `Content-Type: multipart/form-data` .
2018-10-15 14:42:47 +05:30
The `file=` parameter must point to a file on your file system and be preceded
2018-03-27 19:54:05 +05:30
by `@` . For example:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request POST --header "PRIVATE-TOKEN: < your_access_token > " --form "path=api-project" --form "file=@/path/to/file" "https://gitlab.example.com/api/v4/projects/import"
2018-03-27 19:54:05 +05:30
```
2018-11-18 11:00:15 +05:30
cURL doesn't support posting a file from a remote server. Importing a project from a remote server can be accomplished through something like the following:
```python
import requests
2019-12-21 20:55:43 +05:30
from io import BytesIO
2018-11-18 11:00:15 +05:30
2019-12-21 20:55:43 +05:30
s3_file = requests.get(presigned_url)
2018-11-18 11:00:15 +05:30
url = 'https://gitlab.example.com/api/v4/projects/import'
2019-12-21 20:55:43 +05:30
files = {'file': ('file.tar.gz', BytesIO(s3_file.content))}
2018-11-18 11:00:15 +05:30
data = {
"path": "example-project",
"namespace": "example-group"
}
headers = {
2019-02-15 15:39:39 +05:30
'Private-Token': "< your_access_token > "
2018-11-18 11:00:15 +05:30
}
requests.post(url, headers=headers, data=data, files=files)
```
2018-03-27 19:54:05 +05:30
```json
{
"id": 1,
"description": null,
"name": "api-project",
"name_with_namespace": "Administrator / api-project",
"path": "api-project",
"path_with_namespace": "root/api-project",
"created_at": "2018-02-13T09:05:58.023Z",
2020-04-22 19:07:51 +05:30
"import_status": "scheduled",
"correlation_id": "mezklWso3Za",
"failed_relations": []
2018-03-27 19:54:05 +05:30
}
```
2021-02-22 17:27:13 +05:30
NOTE:
2020-06-23 00:09:42 +05:30
The maximum import file size can be set by the Administrator, default is 50MB.
As an administrator, you can modify the maximum import file size. To do so, use the `max_import_size` option in the [Application settings API ](settings.md#change-application-settings ) or the [Admin UI ](../user/admin_area/settings/account_and_limit_settings.md ).
2018-03-27 19:54:05 +05:30
## Import status
Get the status of an import.
2020-05-24 23:13:21 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /projects/:id/import
```
| Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](README.md#namespaced-path-encoding ) owned by the authenticated user |
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/projects/1/import"
2018-03-27 19:54:05 +05:30
```
2020-03-13 15:44:24 +05:30
Status can be one of:
- `none`
- `scheduled`
- `failed`
- `started`
- `finished`
2018-03-27 19:54:05 +05:30
If the status is `failed` , it will include the import error message under `import_error` .
2020-04-22 19:07:51 +05:30
If the status is `failed` , `started` or `finished` , the `failed_relations` array might
be populated with any occurrences of relations that failed to import either due to
unrecoverable errors or because retries were exhausted (a typical example are query timeouts.)
2021-02-22 17:27:13 +05:30
NOTE:
2020-04-22 19:07:51 +05:30
An element's `id` field in `failed_relations` references the failure record, not the relation.
2021-02-22 17:27:13 +05:30
NOTE:
2020-04-22 19:07:51 +05:30
The `failed_relations` array is currently capped to 100 items.
2018-03-27 19:54:05 +05:30
```json
{
"id": 1,
"description": "Itaque perspiciatis minima aspernatur corporis consequatur.",
"name": "Gitlab Test",
"name_with_namespace": "Gitlab Org / Gitlab Test",
"path": "gitlab-test",
"path_with_namespace": "gitlab-org/gitlab-test",
"created_at": "2017-08-29T04:36:44.383Z",
2020-04-22 19:07:51 +05:30
"import_status": "started",
"correlation_id": "mezklWso3Za",
"failed_relations": [
{
"id": 42,
"created_at": "2020-04-02T14:48:59.526Z",
"exception_class": "RuntimeError",
"exception_message": "A failure occurred",
"source": "custom error context",
"relation_name": "merge_requests"
}
]
2018-03-27 19:54:05 +05:30
}
```