{"meta":{"title":"Конечные точки REST API для сред предварительного получения","intro":"Используйте REST API для создания, перечисления, обновления и удаления сред для перехватчики предварительного получения.","product":"REST API","breadcrumbs":[{"href":"/ru/enterprise-server@3.21/rest","title":"REST API"},{"href":"/ru/enterprise-server@3.21/rest/enterprise-admin","title":"Администрирование предприятия"},{"href":"/ru/enterprise-server@3.21/rest/enterprise-admin/pre-receive-environments","title":"Среды предварительного получения"}],"documentType":"article"},"body":"# Конечные точки REST API для сред предварительного получения\n\nИспользуйте REST API для создания, перечисления, обновления и удаления сред для перехватчики предварительного получения.\n\n## Сведения о средах предварительного получения\n\nЭти конечные точки доступны только администраторам сайта, [прошедшим](/ru/enterprise-server@3.21/rest/authentication/authenticating-to-the-rest-api) проверку подлинности. Обычные `404` пользователи получат ответ.\n\n> \\[!NOTE]\n> Эти конечные точки поддерживают проверку подлинности только с помощью personal access token (classic). Дополнительные сведения см. в разделе [Управление личными маркерами доступа](/ru/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#### Среда предварительного получения\n\n| Имя.                  | Тип       | Описание                                                                     |\n| --------------------- | --------- | ---------------------------------------------------------------------------- |\n| `name`                | `string`  | Имя приложения, отображаемое в пользовательском интерфейсе.                  |\n| `image_url`           | `string`  | URL-адрес архива Tarball, который будет скачан и извлечен.                   |\n| `default_environment` | `boolean` | Является ли это средой по умолчанию, с которой поставляется GitHub.          |\n| `download`            | `object`  | Состояние скачивания этой среды.                                             |\n| `hooks_count`         | `integer` | Количество перехватчиков предварительного получения, использующих эту среду. |\n\n#### Скачивание среды предварительного получения\n\n| Имя.            | Тип      | Описание                                                |\n| --------------- | -------- | ------------------------------------------------------- |\n| `state`         | `string` | Состояние последнего скачивания.                        |\n| `downloaded_at` | `string` | Время начала последнего скачивания.                     |\n| `message`       | `string` | В случае неудачи будут выданы все сообщения об ошибках. |\n\nВозможные значения для `state`: `not_started`, `in_progress`, `success` и `failed`.\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 environments\n\n```\nGET /admin/pre-receive-environments\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  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-environments\n```\n\n**Response schema (Status: 200):**\n\nArray of objects:\n\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\n## Create a pre-receive environment\n\n```\nPOST /admin/pre-receive-environments\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 new pre-receive environment's name.\n\n* **`image_url`** (string) (required)\n  URL from which to download a tarball of this environment.\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-environments \\\n  -d '{\n  \"name\": \"DevTools Hook Env\",\n  \"image_url\": \"https://my_file_server/path/to/devtools_env.tar.gz\"\n}'\n```\n\n**Response schema (Status: 201):**\n\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\n## Get a pre-receive environment\n\n```\nGET /admin/pre-receive-environments/{pre_receive_environment_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_environment_id`** (integer) (required)\n  The unique identifier of the pre-receive environment.\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-environments/PRE_RECEIVE_ENVIRONMENT_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a pre-receive environment](#create-a-pre-receive-environment).\n\n## Update a pre-receive environment\n\n```\nPATCH /admin/pre-receive-environments/{pre_receive_environment_id}\n```\n\nYou cannot modify the default environment. If you attempt to modify the default environment, you will receive a 422 Unprocessable Entity response.\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_environment_id`** (integer) (required)\n  The unique identifier of the pre-receive environment.\n\n#### Body parameters\n\n* **`name`** (string)\n  This pre-receive environment's new name.\n\n* **`image_url`** (string)\n  URL from which to download a tarball of this environment.\n\n### HTTP response status codes\n\n* **200** - OK\n\n* **422** - Client Errors\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-environments/PRE_RECEIVE_ENVIRONMENT_ID \\\n  -d '{\n  \"name\": \"DevTools Hook Env\",\n  \"image_url\": \"https://my_file_server/path/to/devtools_env.tar.gz\"\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a pre-receive environment](#create-a-pre-receive-environment).\n\n## Delete a pre-receive environment\n\n```\nDELETE /admin/pre-receive-environments/{pre_receive_environment_id}\n```\n\nIf you attempt to delete an environment that cannot be deleted, you will receive a 422 Unprocessable Entity response.\nThe possible error messages are:\n\nCannot modify or delete the default environment\nCannot delete environment that has hooks\nCannot delete environment when download is in progress\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_environment_id`** (integer) (required)\n  The unique identifier of the pre-receive environment.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n* **422** - Client Errors\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-environments/PRE_RECEIVE_ENVIRONMENT_ID\n```\n\n**Response schema (Status: 204):**\n\n## Start a pre-receive environment download\n\n```\nPOST /admin/pre-receive-environments/{pre_receive_environment_id}/downloads\n```\n\nTriggers a new download of the environment tarball from the environment's image\\_url. When the download is finished, the newly downloaded tarball will overwrite the existing environment.\nIf a download cannot be triggered, you will receive a 422 Unprocessable Entity response.\nThe possible error messages are:\n\nCannot modify or delete the default environment\nCan not start a new download when a download is in progress\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_environment_id`** (integer) (required)\n  The unique identifier of the pre-receive environment.\n\n### HTTP response status codes\n\n* **202** - Accepted\n\n* **422** - Client Errors\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-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads\n```\n\n**Response schema (Status: 202):**\n\n* `url`: string\n* `state`: string\n* `downloaded_at`: string or null\n* `message`: string or null\n\n## Get the download status for a pre-receive environment\n\n```\nGET /admin/pre-receive-environments/{pre_receive_environment_id}/downloads/latest\n```\n\nIn addition to seeing the download status at the \"Get a pre-receive environment\" endpoint, there is also this separate endpoint for just the download status.\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_environment_id`** (integer) (required)\n  The unique identifier of the pre-receive environment.\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-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads/latest\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Start a pre-receive environment download](#start-a-pre-receive-environment-download)."}