{"meta":{"title":"Points de terminaison d’API REST pour hooks de pré-réception","intro":"Utilisez l’API REST pour créer, lister, mettre à jour et supprimer des hooks de pré-réception.","product":"API REST","breadcrumbs":[{"href":"/fr/enterprise-server@3.22/rest","title":"API REST"},{"href":"/fr/enterprise-server@3.22/rest/enterprise-admin","title":"Administration d’entreprise"},{"href":"/fr/enterprise-server@3.22/rest/enterprise-admin/pre-receive-hooks","title":"Hooks de pré-réception"}],"documentType":"article"},"body":"# Points de terminaison d’API REST pour hooks de pré-réception\n\nUtilisez l’API REST pour créer, lister, mettre à jour et supprimer des hooks de pré-réception.\n\n## À propos des hooks de pré-réception\n\nCes points de terminaison sont uniquement disponibles pour les administrateurs de site [authentifiés](/fr/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api). Les utilisateurs normaux recevront une réponse `404`.\n\n> \\[!NOTE]\n> Ces points de terminaison prennent uniquement en charge l’authentification à l’aide d’un personal access token (classic). Pour plus d’informations, consultez « [Gestion de vos jetons d’accès personnels](/fr/enterprise-server@3.22/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) ».\n\n### Attributs d’objet\n\n#### Hook de pré-réception\n\n| Nom                              | Type      | Description                                                                                 |\n| -------------------------------- | --------- | ------------------------------------------------------------------------------------------- |\n| `name`                           | `string`  | Nom du crochet.                                                                             |\n| `script`                         | `string`  | Le script que le hook exécute.                                                              |\n| `script_repository`              | `object`  | Référentiel GitHub où le script est conservé.                                               |\n| `environment`                    | `object`  | Environnement de pré-réception dans lequel le script est exécuté.                           |\n| `enforcement`                    | `string`  | État d’application de ce hook.                                                              |\n| `allow_downstream_configuration` | `boolean` | Indique si l’application peut être remplacée au niveau de l’organisation ou du référentiel. |\n\nLes valeurs possibles pour *enforcement* sont `enabled`, `disabled` et `testing`.\n`disabled` indique que le hook pré-réception ne s’exécute pas.\n`enabled` indique qu’il s’exécute et rejette tous les envois qui entraînent un état différent de zéro.\n`testing` signifie que le script s’exécute, mais n’entraîne pas de rejet des envois.\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):**"}