Skip to main content

Enterprise Server 3.15 is currently available as a release candidate.

The REST API is now versioned. For more information, see "About API versioning."

REST API endpoints for pre-receive environments

Use the REST API to create, list, update and delete environments for pre-receive hooks.

About pre-receive environments

These endpoints are only available to authenticated site administrators. Normal users will receive a 404 response.

These endpoints only support authentication using a personal access token (classic). For more information, see "Managing your personal access tokens."

Object attributes

Pre-receive Environment

NameTypeDescription
namestringThe name of the environment as displayed in the UI.
image_urlstringURL to the tarball that will be downloaded and extracted.
default_environmentbooleanWhether this is the default environment that ships with GitHub Enterprise Server.
downloadobjectThis environment's download status.
hooks_countintegerThe number of pre-receive hooks that use this environment.

Pre-receive Environment Download

NameTypeDescription
statestringThe state of the most recent download.
downloaded_atstringThe time when the most recent download started.
messagestringOn failure, this will have any error messages produced.

Possible values for state are not_started, in_progress, success, failed.

List pre-receive environments

Fine-grained access tokens for "List pre-receive environments"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "List pre-receive environments"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Query parameters
Name, Type, Description
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

Default: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

Default: 1

direction string

The direction to sort the results by.

Default: desc

Can be one of: asc, desc

sort string

Default: created

Can be one of: created, updated, name

HTTP response status codes for "List pre-receive environments"

Status codeDescription
200

OK

Code samples for "List pre-receive environments"

Request example

get/admin/pre-receive-environments
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments

Response

Status: 200
[ { "id": 1, "name": "Default", "image_url": "githubenterprise://internal", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1", "html_url": "https://github.example.com/admin/pre-receive-environments/1", "default_environment": true, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 14, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1/downloads/latest", "state": "not_started", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } }, { "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } } ]

Create a pre-receive environment

Fine-grained access tokens for "Create a pre-receive environment"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Create a pre-receive environment"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Body parameters
Name, Type, Description
name string Required

The new pre-receive environment's name.

image_url string Required

URL from which to download a tarball of this environment.

HTTP response status codes for "Create a pre-receive environment"

Status codeDescription
201

Created

Code samples for "Create a pre-receive environment"

Request example

post/admin/pre-receive-environments
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments \ -d '{"name":"DevTools Hook Env","image_url":"https://my_file_server/path/to/devtools_env.tar.gz"}'

Response

Status: 201
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null } }

Get a pre-receive environment

Fine-grained access tokens for "Get a pre-receive environment"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Get a pre-receive environment"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
pre_receive_environment_id integer Required

The unique identifier of the pre-receive environment.

HTTP response status codes for "Get a pre-receive environment"

Status codeDescription
200

OK

Code samples for "Get a pre-receive environment"

Request example

get/admin/pre-receive-environments/{pre_receive_environment_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID

Response

Status: 200
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null } }

Update a pre-receive environment

You cannot modify the default environment. If you attempt to modify the default environment, you will receive a 422 Unprocessable Entity response.

Fine-grained access tokens for "Update a pre-receive environment"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Update a pre-receive environment"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
pre_receive_environment_id integer Required

The unique identifier of the pre-receive environment.

Body parameters
Name, Type, Description
name string

This pre-receive environment's new name.

image_url string

URL from which to download a tarball of this environment.

HTTP response status codes for "Update a pre-receive environment"

Status codeDescription
200

OK

422

Client Errors

Code samples for "Update a pre-receive environment"

Request example

patch/admin/pre-receive-environments/{pre_receive_environment_id}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID \ -d '{"name":"DevTools Hook Env","image_url":"https://my_file_server/path/to/devtools_env.tar.gz"}'

Response

Status: 200
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } }

Delete a pre-receive environment

If you attempt to delete an environment that cannot be deleted, you will receive a 422 Unprocessable Entity response.

The possible error messages are:

  • Cannot modify or delete the default environment
  • Cannot delete environment that has hooks
  • Cannot delete environment when download is in progress

Fine-grained access tokens for "Delete a pre-receive environment"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Delete a pre-receive environment"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
pre_receive_environment_id integer Required

The unique identifier of the pre-receive environment.

HTTP response status codes for "Delete a pre-receive environment"

Status codeDescription
204

No Content

422

Client Errors

Code samples for "Delete a pre-receive environment"

Request example

delete/admin/pre-receive-environments/{pre_receive_environment_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID

Response

Status: 204

Start a pre-receive environment download

Triggers 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.

If a download cannot be triggered, you will receive a 422 Unprocessable Entity response.

The possible error messages are:

  • Cannot modify or delete the default environment
  • Can not start a new download when a download is in progress

Fine-grained access tokens for "Start a pre-receive environment download"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Start a pre-receive environment download"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
pre_receive_environment_id integer Required

The unique identifier of the pre-receive environment.

HTTP response status codes for "Start a pre-receive environment download"

Status codeDescription
202

Accepted

422

Client Errors

Code samples for "Start a pre-receive environment download"

Request example

post/admin/pre-receive-environments/{pre_receive_environment_id}/downloads
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads

Response

Status: 202
{ "url": "https://github.example.com/api/v3/admin/pre-receive-environments/3/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null }

Get the download status for a pre-receive environment

In 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.

Fine-grained access tokens for "Get the download status for a pre-receive environment"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameters for "Get the download status for a pre-receive environment"

Headers
Name, Type, Description
accept string

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
pre_receive_environment_id integer Required

The unique identifier of the pre-receive environment.

HTTP response status codes for "Get the download status for a pre-receive environment"

Status codeDescription
200

OK

Code samples for "Get the download status for a pre-receive environment"

Request example

get/admin/pre-receive-environments/{pre_receive_environment_id}/downloads/latest
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads/latest

Response

Status: 200
{ "url": "https://github.example.com/api/v3/admin/pre-receive-environments/3/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null }