{"meta":{"title":"REST API endpoints for pre-receive hooks","intro":"Use the REST API to create, list, update and delete pre-receive hooks.","product":"REST API","breadcrumbs":[{"href":"/en/enterprise-server@3.20/rest","title":"REST API"},{"href":"/en/enterprise-server@3.20/rest/enterprise-admin","title":"Enterprise administration"},{"href":"/en/enterprise-server@3.20/rest/enterprise-admin/pre-receive-hooks","title":"Pre-receive hooks"}],"documentType":"article"},"body":"# REST API endpoints for pre-receive hooks\n\nUse the REST API to create, list, update and delete pre-receive hooks.\n\n## About pre-receive hooks\n\nThese endpoints are only available to [authenticated](/en/enterprise-server@3.20/rest/authentication/authenticating-to-the-rest-api) site administrators. Normal users will receive a `404` response.\n\n> \\[!NOTE]\n> These endpoints only support authentication using a personal access token (classic). For more information, see [Managing your personal access tokens](/en/enterprise-server@3.20/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic).\n\n### Object attributes\n\n#### Pre-receive Hook\n\n| Name                             | Type      | Description                                                     |\n| -------------------------------- | --------- | --------------------------------------------------------------- |\n| `name`                           | `string`  | The name of the hook.                                           |\n| `script`                         | `string`  | The script that the hook runs.                                  |\n| `script_repository`              | `object`  | The GitHub repository where the script is kept.                 |\n| `environment`                    | `object`  | The pre-receive environment where the script is executed.       |\n| `enforcement`                    | `string`  | The state of enforcement for this hook.                         |\n| `allow_downstream_configuration` | `boolean` | Whether enforcement can be overridden at the org or repo level. |\n\nPossible values for *enforcement* are `enabled`, `disabled` and`testing`. `disabled` indicates the pre-receive hook will not run. `enabled` indicates it will run and reject\nany pushes that result in a non-zero status. `testing` means the script will run but will not cause any pushes to be rejected.\n\n> \\[!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. 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`** (integer) (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`** (integer) (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`** (integer) (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):**"}