{"meta":{"title":"Pontos de extremidade da API REST para hooks pre-receive","intro":"Use a API REST para criar, listar, atualizar e excluir ganchos de pré-recebimento.","product":"API REST","breadcrumbs":[{"href":"/pt/enterprise-server@3.22/rest","title":"API REST"},{"href":"/pt/enterprise-server@3.22/rest/enterprise-admin","title":"Administração de empresas"},{"href":"/pt/enterprise-server@3.22/rest/enterprise-admin/pre-receive-hooks","title":"Hooks pré-recebimento"}],"documentType":"article"},"body":"# Pontos de extremidade da API REST para hooks pre-receive\n\nUse a API REST para criar, listar, atualizar e excluir ganchos de pré-recebimento.\n\n## Sobre hooks pre-receive\n\nEsses endpoints só estão disponíveis para administradores de site [autenticados](/pt/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api). Os usuários normais receberão uma resposta `404`.\n\n> \\[!NOTE]\n> Esses pontos de extremidade só dão suporte à autenticação por meio de um personal access token (classic). Para saber mais, confira [Gerenciar seus tokens de acesso pessoal](/pt/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 do objeto\n\n#### Hook pre-receive\n\n| Nome                             | Tipo      | Descrição                                                                      |\n| -------------------------------- | --------- | ------------------------------------------------------------------------------ |\n| `name`                           | `string`  | O nome do hook.                                                                |\n| `script`                         | `string`  | O script que o hook executa.                                                   |\n| `script_repository`              | `object`  | O GitHub repositório em que o script é mantido.                                |\n| `environment`                    | `object`  | O ambiente de pre-receive onde o script é executado.                           |\n| `enforcement`                    | `string`  | O estado de aplicação para este hook.                                          |\n| `allow_downstream_configuration` | `boolean` | Se a aplicação pode ser substituída no nível da organização ou do repositório. |\n\nOs possíveis valores para *aplicação* são `enabled`, `disabled` e `testing`.\n`disabled` indica que o gancho de pré-recebimento não será executado.\n`enabled` indica que ele será executado e rejeitará os pushes que resultem em um status diferente de zero.\n`testing` significa que o script será executado, mas não fará com que nenhum push seja rejeitado.\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):**"}