---
title: "Create or update an organization secret"
method: PUT
path: "/orgs/{org}/codespaces/secrets/{secret_name}"
tags: ["codespaces"]
---

# Create or update an organization secret

`PUT /orgs/{org}/codespaces/secrets/{secret_name}`

Creates or updates an organization development environment secret with an encrypted value. Encrypt your secret using
[LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages). For more information, see "[Encrypting secrets for the REST API](https://docs.github.com/enterprise-cloud@latest/rest/guides/encrypting-secrets-for-the-rest-api)."

OAuth app tokens and personal access tokens (classic) need the `admin:org` scope to use this endpoint.

## Path parameters

- `org` string, required
- `secret_name` string, required

## Request body

- object
  - `encrypted_value` string — The value for your secret, encrypted with [LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages) using the public key retrieved from the [Get an organization public key](https://docs.github.com/enterprise-cloud@latest/rest/codespaces/organization-secrets#get-an-organization-public-key) endpoint.
  - `key_id` string — The ID of the key you used to encrypt the secret.
  - `visibility` 'all' | 'private' | 'selected', required — Which type of organization repositories have access to the organization secret. `selected` means only the repositories specified by `selected_repository_ids` can access the secret.
  - `selected_repository_ids` integer[] — An array of repository IDs that can access the organization secret. You can only provide a list of repository IDs when the `visibility` is set to `selected`. You can manage the list of selected repositories using the [List selected repositories for an organization secret](https://docs.github.com/enterprise-cloud@latest/rest/codespaces/organization-secrets#list-selected-repositories-for-an-organization-secret), [Set selected repositories for an organization secret](https://docs.github.com/enterprise-cloud@latest/rest/codespaces/organization-secrets#set-selected-repositories-for-an-organization-secret), and [Remove selected repository from an organization secret](https://docs.github.com/enterprise-cloud@latest/rest/codespaces/organization-secrets#remove-selected-repository-from-an-organization-secret) endpoints.

## Response `201`

Response when creating a secret

- EmptyObject — An object without any properties.

## Other responses

- `204` — Response when updating a secret
- `404` — Resource not found
- `422` — Validation failed, or the endpoint has been spammed.

---

[API](https://skmtc.net/github/apis/ghec.md) · [All operations](https://skmtc.net/github/apis/ghec/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/ghec/revisions/8ae6d0c8716e/schema)
