# REST-API-Endpunkte für Bereitstellungsschlüssel

Verwende die REST-API, um Bereitstellungsschlüssel zu erstellen und zu verwalten.

## Informationen zu Bereitstellungsschlüsseln

Du kannst Projekte aus einem Repository in Ihre GitHub Enterprise Server-Instance auf deinem Server starten, indem du einen Bereitstellungsschlüssel verwendest. Dabei handelt es sich um einen SSH-Schlüssel, der Zugriff auf ein einzelnes Repository gewährt. GitHub fügt den öffentlichen Teil des Schlüssels direkt an dein Repository anstatt an ein persönliches Konto an, und der private Teil des Schlüssels verbleibt auf deinem Server. Weitere Informationen finden Sie unter [Durchführung von Bereitstellungen](/de/enterprise-server@3.18/rest/guides/delivering-deployments).

Bereitstellungsschlüssel können entweder mithilfe der folgenden API-Endpunkte oder mithilfe der GitHub Webschnittstelle eingerichtet werden. Weitere Informationen zum Einrichten von Bereitstellungsschlüsseln in der Webschnittstelle findest du unter [Verwalten von Bereitstellungsschlüsseln](/de/enterprise-server@3.18/authentication/connecting-to-github-with-ssh/managing-deploy-keys).

Möglicherweise können Sie keine Bereitstellungsschlüssel erstellen, wenn Ihr Organisations- oder Unternehmensbesitzer eine Richtlinie festgelegt hat, um die Verwendung einzuschränken. Wenn diese Richtlinie auf Organisations- oder Unternehmensebene aktiviert ist, können vorhandene Bereitstellungsschlüssel deaktiviert werden. Weitere Informationen findest du unter [Richtlinien zur Verwaltung von Repositories in Ihrem Unternehmen erzwingen](/de/enterprise-server@3.18/admin/policies/enforcing-policies-for-your-enterprise/enforcing-repository-management-policies-in-your-enterprise#enforcing-a-policy-for-deploy-keys) und [Einschränkung der Deployment-Keys in Ihrer Organisation](/de/enterprise-server@3.18/organizations/managing-organization-settings/restricting-deploy-keys-in-your-organization).

In einigen Fällen wird ein Bereitstellungsschlüssel durch andere Aktivitäten gelöscht:

* Wenn der Bereitstellungsschlüssel mit einem personal access token erstellt wurde, führt das Löschen von personal access token auch zur Löschung des Bereitstellungsschlüssels. Regenerieren des personal access token löscht den Bereitstellungsschlüssel nicht.
* Wenn der Bereitstellungsschlüssel mit einem OAuth app Token erstellt wird, wird durch das Widerrufen des Tokens auch der Bereitstellungsschlüssel gelöscht.

Im Gegensatz dazu werden diese Vorgänge keinen Deploy-Key löschen:

* Wenn der Bereitstellungsschlüssel mit einem GitHub App Benutzerzugriffstoken erstellt wird, löscht das Widerrufen des Tokens nicht den Bereitstellungsschlüssel.
* Wenn der Bereitstellungsschlüssel mit einem GitHub App Installationszugriffstoken erstellt wird, wird beim Deinstallieren oder Löschen der App der Bereitstellungsschlüssel nicht gelöscht.
* Wenn der Bereitstellungsschlüssel mit einem personal access token erstellt wird, führt das Neugenerieren von personal access token nicht zur Löschung des Bereitstellungsschlüssels.

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.

## List deploy keys

```
GET /repos/{owner}/{repo}/keys
```

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

* **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

* **`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`

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys
```

**Response schema (Status: 200):**

Array of `Deploy Key`:

* `id`: required, integer
* `key`: required, string
* `url`: required, string
* `title`: required, string
* `verified`: required, boolean
* `created_at`: required, string
* `read_only`: required, boolean
* `added_by`: string or null
* `last_used`: string or null, format: date-time
* `enabled`: boolean

## Create a deploy key

```
POST /repos/{owner}/{repo}/keys
```

You can create a read-only deploy key.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

* **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

#### Body parameters

* **`title`** (string)
  A name for the key.

* **`key`** (string) (required)
  The contents of the key.

* **`read_only`** (boolean)
  If true, the key will only be able to read repository contents. Otherwise, the key will be able to read and write.
  Deploy keys with write access can perform the same actions as an organization member with admin access, or a collaborator on a personal repository. For more information, see "Repository permission levels for an organization" and "Permission levels for a user account repository."

### HTTP response status codes

* **201** - Created

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys \
  -d '{
  "title": "octocat@octomac",
  "key": "ssh-rsa AAA...",
  "read_only": true
}'
```

**Response schema (Status: 201):**

* `id`: required, integer
* `key`: required, string
* `url`: required, string
* `title`: required, string
* `verified`: required, boolean
* `created_at`: required, string
* `read_only`: required, boolean
* `added_by`: string or null
* `last_used`: string or null, format: date-time
* `enabled`: boolean

## Get a deploy key

```
GET /repos/{owner}/{repo}/keys/{key_id}
```

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

* **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

* **`key_id`** (integer) (required)
  The unique identifier of the key.

### HTTP response status codes

* **200** - OK

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys/KEY_ID
```

**Response schema (Status: 200):**

Same response schema as [Create a deploy key](#create-a-deploy-key).

## Delete a deploy key

```
DELETE /repos/{owner}/{repo}/keys/{key_id}
```

Deploy keys are immutable. If you need to update a key, remove the key and create a new one instead.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

* **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

* **`key_id`** (integer) (required)
  The unique identifier of the key.

### HTTP response status codes

* **204** - No Content

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys/KEY_ID
```

**Response schema (Status: 204):**