{"meta":{"title":"Pontos de extremidade da API REST para ambientes de pré-recebimento","intro":"Use a API REST para criar, listar, atualizar e excluir ambientes para 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-environments","title":"Ambientes de Pré-recebimento"}],"documentType":"article"},"body":"# Pontos de extremidade da API REST para ambientes de pré-recebimento\n\nUse a API REST para criar, listar, atualizar e excluir ambientes para ganchos de pré-recebimento.\n\n## Sobre os ambientes de pré-recebimento\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#### Ambiente pre-receive\n\n| Nome                  | Tipo      | Descrição                                                    |\n| --------------------- | --------- | ------------------------------------------------------------ |\n| `name`                | `string`  | O nome do ambiente conforme exibido na interface do usuário. |\n| `image_url`           | `string`  | URL do tarball que será baixado e extraído.                  |\n| `default_environment` | `boolean` | Se esse é o ambiente padrão que é fornecido com GitHub.      |\n| `download`            | `object`  | Status do download deste ambiente.                           |\n| `hooks_count`         | `integer` | O número de hooks de pre-receive que usam este ambiente.     |\n\n#### Download do ambiente pre-receive\n\n| Nome            | Tipo     | Descrição                                                              |\n| --------------- | -------- | ---------------------------------------------------------------------- |\n| `state`         | `string` | O estado do download mais recente.                                     |\n| `downloaded_at` | `string` | A hora em que o download mais recente começou.                         |\n| `message`       | `string` | Em caso de falha, isso conterá quaisquer mensagens de erro produzidas. |\n\nOs valores possíveis para `state` são `not_started`, `in_progress`, `success` e `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)."}