{"meta":{"title":"pre-receive 環境用の REST API エンドポイント","intro":"この REST API を使って、pre-receive フックの環境を作成、一覧表示、更新、削除します。","product":"REST API","breadcrumbs":[{"href":"/ja/enterprise-server@3.22/rest","title":"REST API"},{"href":"/ja/enterprise-server@3.22/rest/enterprise-admin","title":"企業管理"},{"href":"/ja/enterprise-server@3.22/rest/enterprise-admin/pre-receive-environments","title":"受信前環境"}],"documentType":"article"},"body":"# pre-receive 環境用の REST API エンドポイント\n\nこの REST API を使って、pre-receive フックの環境を作成、一覧表示、更新、削除します。\n\n## pre-receive 環境について\n\nこれらのエンドポイントは、[認証された](/ja/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api)サイト管理者のみが使用できます。 通常のユーザーは `404` 応答を受け取ります。\n\n> \\[!NOTE]\n> これらのエンドポイントでは、personal access token (classic) を使う認証のみがサポートされます。 詳しくは、「[個人用アクセス トークンを管理する](/ja/enterprise-server@3.22/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)」をご覧ください。\n\n### オブジェクトの属性\n\n#### pre-receive 環境\n\n| 名前                    | タイプ       | 説明                             |\n| --------------------- | --------- | ------------------------------ |\n| `name`                | `string`  | UI に表示される環境の名前。                |\n| `image_url`           | `string`  | ダウンロードおよび抽出される tarball への URL。 |\n| `default_environment` | `boolean` | これが GitHubに付属する既定の環境かどうか。      |\n| `download`            | `object`  | この環境のダウンロードステータス。              |\n| `hooks_count`         | `integer` | この環境を使用する pre-receive フックの数。   |\n\n#### pre-receive 環境のダウンロード\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)."}