Sample - GitHub REST API
PUT/repos/{owner}/{repo}/environments/{environment_name}

Create or update an environment

Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments."

[!NOTE] To create or update name patterns that branches must match in order to deploy to this environment, see "Deployment branch policies."

[!NOTE] To create or update secrets for an environment, see "GitHub Actions secrets."

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters · 4 body fields
ownerstringrequired
The account owner of the repository. The name is not case sensitive.
repostringrequired
The name of the repository without the `.git` extension. The name is not case sensitive.
environment_namestringrequired
The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with `%2F`.
wait_timerintegeroptional
The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).
prevent_self_reviewbooleanoptional
Whether or not a user who created the job is prevented from approving their own job.
reviewersarray<object>optional
The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed.
deployment_branch_policyobjectoptional
The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.

2 status codes
200Response
idintegerrequired
The id of the environment.
node_idstringrequired
namestringrequired
The name of the environment.
urlstringrequired
html_urlstringrequired
created_atstringrequired
The time that the environment was created, in ISO 8601 format.
updated_atstringrequired
The time that the environment was last updated, in ISO 8601 format.
protection_rulesarray<object>optional
Built-in deployment protection rules for the environment.
deployment_branch_policyobjectoptional
The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.
422Validation error when the environment name is invalid or when `protected_branches` and `custom_branch_policies` in `deployment_branch_policy` are set to the same value
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional

Error handling

A 422 is returned: Validation error when the environment name is invalid or when protected_branches and custom_branch_policies in deployment_branch_policy are set to the same value.