# 사전 수신 환경에 대한 REST API 엔드포인트

REST API를 사용하면 사전 수신 후크에 대한 환경을 만들고, 나열하고, 업데이트하고, 삭제할 수 있습니다.

## 사전 수신 환경에 대하여

이러한 엔드포인트는 [인증된](/ko/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api) 사이트 관리자만 사용할 수 있습니다. 일반 사용자는 `404` 응답을 받게 됩니다.

> \[!NOTE]
> 이러한 엔드포인트는 personal access token (classic)을(를) 사용하는 인증만 지원합니다. 자세한 내용은 [개인용 액세스 토큰 관리](/ko/enterprise-server@3.22/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)을(를) 참조하세요.

### 개체 특성

#### 사전 수신 환경

| 이름                             | 형식        | 설명                          |
| ------------------------------ | --------- | --------------------------- |
| `name`                         | `string`  | UI에 표시되는 환경 이름입니다.          |
| `image_url`                    | `string`  | 다운로드하고 추출할 tarball의 URL입니다. |
| `default_environment`          | `boolean` |                             |
| GitHub와 함께 제공되는 기본 환경인지 여부입니다. |           |                             |
| `download`                     | `object`  | 이 환경의 다운로드 상태입니다.           |
| `hooks_count`                  | `integer` | 이 환경을 사용하는 사전 수신 후크 수입니다.   |

#### 사전 수신 환경 다운로드

| 이름              | 형식       | 설명                     |
| --------------- | -------- | ---------------------- |
| `state`         | `string` | 가장 최근 다운로드의 상태입니다.     |
| `downloaded_at` | `string` | 가장 최근 다운로드가 시작된 시간입니다. |
| `message`       | `string` | 오류 발생 시 생성된 오류 메시지입니다. |

`state`의 가능한 값은 `not_started`, `in_progress`, `success`, `failed`입니다.

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.

## List pre-receive environments

```
GET /admin/pre-receive-environments
```

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

* **`direction`** (string)
  The direction to sort the results by.
  Default: `desc`
  Can be one of: `asc`, `desc`

* **`sort`** (string)
  Default: `created`
  Can be one of: `created`, `updated`, `name`

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments
```

**Response schema (Status: 200):**

Array of objects:

* `id`: integer, format: int64
* `name`: string
* `image_url`: string
* `url`: string
* `html_url`: string
* `default_environment`: boolean
* `created_at`: string
* `hooks_count`: integer
* `download`: object:
  * `url`: string
  * `state`: string
  * `downloaded_at`: string or null
  * `message`: string or null

## Create a pre-receive environment

```
POST /admin/pre-receive-environments
```

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Body parameters

* **`name`** (string) (required)
  The new pre-receive environment's name.

* **`image_url`** (string) (required)
  URL from which to download a tarball of this environment.

### HTTP response status codes

* **201** - Created

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments \
  -d '{
  "name": "DevTools Hook Env",
  "image_url": "https://my_file_server/path/to/devtools_env.tar.gz"
}'
```

**Response schema (Status: 201):**

* `id`: integer, format: int64
* `name`: string
* `image_url`: string
* `url`: string
* `html_url`: string
* `default_environment`: boolean
* `created_at`: string
* `hooks_count`: integer
* `download`: object:
  * `url`: string
  * `state`: string
  * `downloaded_at`: string or null
  * `message`: string or null

## Get a pre-receive environment

```
GET /admin/pre-receive-environments/{pre_receive_environment_id}
```

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`pre_receive_environment_id`** (integer) (required)
  The unique identifier of the pre-receive environment.

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID
```

**Response schema (Status: 200):**

Same response schema as [Create a pre-receive environment](#create-a-pre-receive-environment).

## Update a pre-receive environment

```
PATCH /admin/pre-receive-environments/{pre_receive_environment_id}
```

You cannot modify the default environment. If you attempt to modify the default environment, you will receive a 422 Unprocessable Entity response.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`pre_receive_environment_id`** (integer) (required)
  The unique identifier of the pre-receive environment.

#### Body parameters

* **`name`** (string)
  This pre-receive environment's new name.

* **`image_url`** (string)
  URL from which to download a tarball of this environment.

### HTTP response status codes

* **200** - OK

* **422** - Client Errors

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID \
  -d '{
  "name": "DevTools Hook Env",
  "image_url": "https://my_file_server/path/to/devtools_env.tar.gz"
}'
```

**Response schema (Status: 200):**

Same response schema as [Create a pre-receive environment](#create-a-pre-receive-environment).

## Delete a pre-receive environment

```
DELETE /admin/pre-receive-environments/{pre_receive_environment_id}
```

If you attempt to delete an environment that cannot be deleted, you will receive a 422 Unprocessable Entity response.
The possible error messages are:

Cannot modify or delete the default environment
Cannot delete environment that has hooks
Cannot delete environment when download is in progress

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`pre_receive_environment_id`** (integer) (required)
  The unique identifier of the pre-receive environment.

### HTTP response status codes

* **204** - No Content

* **422** - Client Errors

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID
```

**Response schema (Status: 204):**

## Start a pre-receive environment download

```
POST /admin/pre-receive-environments/{pre_receive_environment_id}/downloads
```

Triggers a new download of the environment tarball from the environment's image\_url. When the download is finished, the newly downloaded tarball will overwrite the existing environment.
If a download cannot be triggered, you will receive a 422 Unprocessable Entity response.
The possible error messages are:

Cannot modify or delete the default environment
Can not start a new download when a download is in progress

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`pre_receive_environment_id`** (integer) (required)
  The unique identifier of the pre-receive environment.

### HTTP response status codes

* **202** - Accepted

* **422** - Client Errors

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads
```

**Response schema (Status: 202):**

* `url`: string
* `state`: string
* `downloaded_at`: string or null
* `message`: string or null

## Get the download status for a pre-receive environment

```
GET /admin/pre-receive-environments/{pre_receive_environment_id}/downloads/latest
```

In addition to seeing the download status at the "Get a pre-receive environment" endpoint, there is also this separate endpoint for just the download status.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`pre_receive_environment_id`** (integer) (required)
  The unique identifier of the pre-receive environment.

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads/latest
```

**Response schema (Status: 200):**

Same response schema as [Start a pre-receive environment download](#start-a-pre-receive-environment-download).