# 사전 수신 후크에 대한 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`  | 후크의 이름입니다.                             |
| `script`                         | `string`  | 후크가 실행하는 코드 스크립트입니다.                   |
| `script_repository`              | `object`  | 스크립트가 유지되는 GitHub 리포지토리입니다.            |
| `environment`                    | `object`  | 스크립트가 실행되는 사전 수신 환경입니다.                |
| `enforcement`                    | `string`  | 이 후크의 적용 상태입니다.                        |
| `allow_downstream_configuration` | `boolean` | 조직 또는 리포지토리 수준에서 적용을 재정의할 수 있는지 여부입니다. |

*적용* 가능한 값은 `enabled`, `disabled`, `testing`입니다.
`disabled`는 사전 수신 후크가 실행되지 않음을 나타냅니다.
`enabled`는 0이 아닌 상태가 되는 모든 푸시를 실행하고 거부함을 나타냅니다.
`testing`은 스크립트가 실행되지만 푸시가 거부되지 않음을 의미합니다.

> \[!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 hooks

```
GET /admin/pre-receive-hooks
```

### 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)
  The property to sort the results by.
  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-hooks
```

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

Array of objects:

* `id`: integer
* `name`: string
* `enforcement`: string
* `script`: string
* `script_repository`: object:
  * `id`: integer
  * `full_name`: string
  * `url`: string
  * `html_url`: string
* `environment`: object:
  * `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
* `allow_downstream_configuration`: boolean

## Create a pre-receive hook

```
POST /admin/pre-receive-hooks
```

### Parameters

#### Headers

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

#### Body parameters

* **`name`** (string) (required)
  The name of the hook.

* **`script`** (string) (required)
  The script that the hook runs.

* **`script_repository`** (object) (required)
  The GitHub repository where the script is kept.

* **`environment`** (object) (required)
  The pre-receive environment where the script is executed.

* **`enforcement`** (string)
  The state of enforcement for this hook. default: disabled

* **`allow_downstream_configuration`** (boolean)
  Whether enforcement can be overridden at the org or repo level. default: false

### HTTP response status codes

* **201** - Created

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks \
  -d '{
  "name": "Check Commits",
  "script": "scripts/commit_check.sh",
  "enforcement": "disabled",
  "allow_downstream_configuration": false,
  "script_repository": {
    "full_name": "DevIT/hooks"
  },
  "environment": {
    "id": 2
  }
}'
```

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

* `id`: integer
* `name`: string
* `enforcement`: string
* `script`: string
* `script_repository`: object:
  * `id`: integer
  * `full_name`: string
  * `url`: string
  * `html_url`: string
* `environment`: object:
  * `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
* `allow_downstream_configuration`: boolean

## Get a pre-receive hook

```
GET /admin/pre-receive-hooks/{pre_receive_hook_id}
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`pre_receive_hook_id`** (string) (required)
  The unique identifier of the pre-receive hook.

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

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

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

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

## Update a pre-receive hook

```
PATCH /admin/pre-receive-hooks/{pre_receive_hook_id}
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`pre_receive_hook_id`** (string) (required)
  The unique identifier of the pre-receive hook.

#### Body parameters

* **`name`** (string)
  The name of the hook.

* **`script`** (string)
  The script that the hook runs.

* **`script_repository`** (object)
  The GitHub repository where the script is kept.

* **`environment`** (object)
  The pre-receive environment where the script is executed.

* **`enforcement`** (string)
  The state of enforcement for this hook.

* **`allow_downstream_configuration`** (boolean)
  Whether enforcement can be overridden at the org or repo level.

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \
  -d '{
  "name": "Check Commits",
  "environment": {
    "id": 1
  },
  "allow_downstream_configuration": true
}'
```

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

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

## Delete a pre-receive hook

```
DELETE /admin/pre-receive-hooks/{pre_receive_hook_id}
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`pre_receive_hook_id`** (string) (required)
  The unique identifier of the pre-receive hook.

### HTTP response status codes

* **204** - No Content

### Code examples

#### Example

**Request:**

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

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