{"meta":{"title":"プリレシーブフック用の REST API エンドポイント","intro":"REST API を使い、pre-receive フックを作成、一覧表示、更新、削除します。","product":"REST API","breadcrumbs":[{"href":"/ja/enterprise-server@3.21/rest","title":"REST API"},{"href":"/ja/enterprise-server@3.21/rest/enterprise-admin","title":"企業管理"},{"href":"/ja/enterprise-server@3.21/rest/enterprise-admin/pre-receive-hooks","title":"pre-receive フック"}],"documentType":"article"},"body":"# プリレシーブフック用の REST API エンドポイント\n\nREST API を使い、pre-receive フックを作成、一覧表示、更新、削除します。\n\n## pre-receiveフックについて\n\nこれらのエンドポイントは、[認証された](/ja/enterprise-server@3.21/rest/authentication/authenticating-to-the-rest-api)サイト管理者のみが使用できます。 通常のユーザーは `404` 応答を受け取ります。\n\n> \\[!NOTE]\n> これらのエンドポイントでは、personal access token (classic) を使う認証のみがサポートされます。 詳しくは、「[個人用アクセス トークンを管理する](/ja/enterprise-server@3.21/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)」をご覧ください。\n\n### オブジェクトの属性\n\n#### pre-receive フック\n\n| 名前                               | タイプ       | 説明                                   |\n| -------------------------------- | --------- | ------------------------------------ |\n| `name`                           | `string`  | フックの名前。                              |\n| `script`                         | `string`  | フックが実行するスクリプト。                       |\n| `script_repository`              | `object`  | スクリプトが保持されているGitHub リポジトリ。           |\n| `environment`                    | `object`  | スクリプトが実行される pre-receive 環境。          |\n| `enforcement`                    | `string`  | このフックの適用状態。                          |\n| `allow_downstream_configuration` | `boolean` | 組織レベルまたはリポジトリレベルでの強制のオーバーライドが可能かどうか。 |\n\n\\_適用\\_に使用できる値は `enabled`、`disabled`と`testing`です。\n`disabled` は、pre-receive フックが実行されないことを示します。\n`enabled` は、実行時に結果がゼロ以外のステータスとなった場合にプッシュを拒否することを示しています。\n`testing` は、スクリプトは実行されるが、プッシュが拒否されないことを示します。\n\n> \\[!NOTE]\n> 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.\n\n## List pre-receive hooks\n\n```\nGET /admin/pre-receive-hooks\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n* **`direction`** (string)\n  The direction to sort the results by.\n  Default: `desc`\n  Can be one of: `asc`, `desc`\n\n* **`sort`** (string)\n  The property to sort the results by.\n  Default: `created`\n  Can be one of: `created`, `updated`, `name`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks\n```\n\n**Response schema (Status: 200):**\n\nArray of objects:\n\n* `id`: integer\n* `name`: string\n* `enforcement`: string\n* `script`: string\n* `script_repository`: object:\n  * `id`: integer\n  * `full_name`: string\n  * `url`: string\n  * `html_url`: string\n* `environment`: object:\n  * `id`: integer, format: int64\n  * `name`: string\n  * `image_url`: string\n  * `url`: string\n  * `html_url`: string\n  * `default_environment`: boolean\n  * `created_at`: string\n  * `hooks_count`: integer\n  * `download`: object:\n    * `url`: string\n    * `state`: string\n    * `downloaded_at`: string or null\n    * `message`: string or null\n* `allow_downstream_configuration`: boolean\n\n## Create a pre-receive hook\n\n```\nPOST /admin/pre-receive-hooks\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Body parameters\n\n* **`name`** (string) (required)\n  The name of the hook.\n\n* **`script`** (string) (required)\n  The script that the hook runs.\n\n* **`script_repository`** (object) (required)\n  The GitHub repository where the script is kept.\n\n* **`environment`** (object) (required)\n  The pre-receive environment where the script is executed.\n\n* **`enforcement`** (string)\n  The state of enforcement for this hook. default: disabled\n\n* **`allow_downstream_configuration`** (boolean)\n  Whether enforcement can be overridden at the org or repo level. default: false\n\n### HTTP response status codes\n\n* **201** - Created\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks \\\n  -d '{\n  \"name\": \"Check Commits\",\n  \"script\": \"scripts/commit_check.sh\",\n  \"enforcement\": \"disabled\",\n  \"allow_downstream_configuration\": false,\n  \"script_repository\": {\n    \"full_name\": \"DevIT/hooks\"\n  },\n  \"environment\": {\n    \"id\": 2\n  }\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `id`: integer\n* `name`: string\n* `enforcement`: string\n* `script`: string\n* `script_repository`: object:\n  * `id`: integer\n  * `full_name`: string\n  * `url`: string\n  * `html_url`: string\n* `environment`: object:\n  * `id`: integer, format: int64\n  * `name`: string\n  * `image_url`: string\n  * `url`: string\n  * `html_url`: string\n  * `default_environment`: boolean\n  * `created_at`: string\n  * `hooks_count`: integer\n  * `download`: object:\n    * `url`: string\n    * `state`: string\n    * `downloaded_at`: string or null\n    * `message`: string or null\n* `allow_downstream_configuration`: boolean\n\n## Get a pre-receive hook\n\n```\nGET /admin/pre-receive-hooks/{pre_receive_hook_id}\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`pre_receive_hook_id`** (string) (required)\n  The unique identifier of the pre-receive hook.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a pre-receive hook](#create-a-pre-receive-hook).\n\n## Update a pre-receive hook\n\n```\nPATCH /admin/pre-receive-hooks/{pre_receive_hook_id}\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`pre_receive_hook_id`** (string) (required)\n  The unique identifier of the pre-receive hook.\n\n#### Body parameters\n\n* **`name`** (string)\n  The name of the hook.\n\n* **`script`** (string)\n  The script that the hook runs.\n\n* **`script_repository`** (object)\n  The GitHub repository where the script is kept.\n\n* **`environment`** (object)\n  The pre-receive environment where the script is executed.\n\n* **`enforcement`** (string)\n  The state of enforcement for this hook.\n\n* **`allow_downstream_configuration`** (boolean)\n  Whether enforcement can be overridden at the org or repo level.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \\\n  -d '{\n  \"name\": \"Check Commits\",\n  \"environment\": {\n    \"id\": 1\n  },\n  \"allow_downstream_configuration\": true\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a pre-receive hook](#create-a-pre-receive-hook).\n\n## Delete a pre-receive hook\n\n```\nDELETE /admin/pre-receive-hooks/{pre_receive_hook_id}\n```\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`pre_receive_hook_id`** (string) (required)\n  The unique identifier of the pre-receive hook.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID\n```\n\n**Response schema (Status: 204):**"}