{"meta":{"title":"Puntos de conexión de API REST para ganchos previos a la recepción","intro":"Usa la API REST para crear, enumerar, actualizar y eliminar enlaces previos a la recepción.","product":"REST API","breadcrumbs":[{"href":"/es/enterprise-server@3.22/rest","title":"REST API"},{"href":"/es/enterprise-server@3.22/rest/enterprise-admin","title":"Administración empresarial"},{"href":"/es/enterprise-server@3.22/rest/enterprise-admin/pre-receive-hooks","title":"Ganchos de pre-recepción"}],"documentType":"article"},"body":"# Puntos de conexión de API REST para ganchos previos a la recepción\n\nUsa la API REST para crear, enumerar, actualizar y eliminar enlaces previos a la recepción.\n\n## Acerca de ganchos de pre-recepción\n\nEstos puntos de conexión solo están disponibles para los administradores de sitios [autenticados](/es/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api). Los usuarios normales recibirán una respuesta `404`.\n\n> \\[!NOTE]\n> Estos puntos de conexión solo admiten la autenticación mediante personal access token (classic). Para más información, consulta [Administración de tokens de acceso personal](/es/enterprise-server@3.22/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic).\n\n### Atributos de objeto\n\n#### Ganchos de pre-recepción\n\n| Nombre                           | Tipo      | Descripción                                                                         |\n| -------------------------------- | --------- | ----------------------------------------------------------------------------------- |\n| `name`                           | `string`  | El nombre del gancho.                                                               |\n| `script`                         | `string`  | El script que ejecuta el gancho.                                                    |\n| `script_repository`              | `object`  | Repositorio GitHub donde se mantiene el script.                                     |\n| `environment`                    | `object`  | El ambiente de pre-recepción en donde se ejecuta el script.                         |\n| `enforcement`                    | `string`  | El estado de las imposiciones para este gancho.                                     |\n| `allow_downstream_configuration` | `boolean` | Si las imposiciones pueden o no ignorarse a nivel de organización o de repositorio. |\n\nLos valores posibles para la *aplicación* son `enabled`, `disabled` y `testing`.\n`disabled` indica que no se ejecutará el enlace previo a la recepción.\n`enabled` indica que se ejecutará y rechazará cualquier inserción que dé como resultado un estado distinto de cero.\n`testing` indica que el script se ejecutará pero no provocará el rechazo de ningún envío.\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):**"}