Skip to main content
Die REST-API verfügt jetzt über eine Versionskontrolle. Weitere Informationen findest du unter Informationen zur API-Versionsverwaltung.

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 GitHub.com 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 dein persönliches Konto an, und der private Teil des Schlüssels verbleibt auf deinem Server. Weitere Informationen findest du unter Übermitteln von Bereitstellungen.

Bereitstellungsschlüssel können mithilfe der folgenden API-Endpunkte oder mithilfe der Webschnittstelle GitHub eingerichtet werden. Weitere Informationen zum Einrichten von Bereitstellungsschlüsseln in der Webschnittstelle findest du unter „Verwalten von Bereitstellungsschlüsseln“.

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

  • Wenn der Bereitstellungsschlüssel mit einem personal access token erstellt wird, wird er beim Löschen von personal access token ebenfalls gelöscht. Durch das erneute Generieren von personal access token wird die Bereitstellungsschlüssel nicht gelöscht.
  • Wenn der Bereitstellungsschlüssel mit einem OAuth app-Token erstellt wird, wird durch das Widerrufen des Tokens auch der Bereitstellungsschlüssel gelöscht.

Umgekehrt werden diese Aktivitäten keine Bereitstellungsschlüssel löschen:

  • Wenn der Bereitstellungsschlüssel mit einem GitHub App-Benutzerzugriffstoken erstellt wird, löscht das Widerrufen des Tokens den Bereitstellungsschlüssel nicht.
  • Wenn der Bereitstellungsschlüssel mit einem GitHub App-Installationszugriffstoken erstellt wird, wird der Bereitstellungsschlüssel durch das Deinstallieren oder Löschen der App nicht gelöscht.
  • Wenn der Bereitstellungsschlüssel mit einem personal access token erstellt wird, wird er beim erneuten Generieren von personal access token nicht gelöscht.

List deploy keys

Differenzierte Zugriffstoken für "List deploy keys"

Dieser Endpunkt funktioniert mit den folgenden Tokentypen.:

Das Token muss einen der folgenden Berechtigungssätze aufweisen.:

  • administration:read

Parameter für „List deploy keys“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
owner string Erforderlich

The account owner of the repository. The name is not case sensitive.

repo string Erforderlich

The name of the repository without the .git extension. The name is not case sensitive.

Abfrageparameter
Name, type, BESCHREIBUNG
per_page integer

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

Standard: 30

page integer

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

Standard: 1

HTTP-Antwortstatuscodes für „List deploy keys“

StatuscodeBESCHREIBUNG
200

OK

Codebeispiele für „List deploy keys“

Beispiel für eine Anfrage

get/repos/{owner}/{repo}/keys
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/keys

Response

Status: 200
[ { "id": 1, "key": "ssh-rsa AAA...", "url": "https://api.github.com/repos/octocat/Hello-World/keys/1", "title": "octocat@octomac", "verified": true, "created_at": "2014-12-10T15:53:42Z", "read_only": true, "added_by": "octocat", "last_used": "2022-01-10T15:53:42Z" } ]

Create a deploy key

You can create a read-only deploy key.

Differenzierte Zugriffstoken für "Create a deploy key"

Dieser Endpunkt funktioniert mit den folgenden Tokentypen.:

Das Token muss einen der folgenden Berechtigungssätze aufweisen.:

  • administration:write

Parameter für „Create a deploy key“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
owner string Erforderlich

The account owner of the repository. The name is not case sensitive.

repo string Erforderlich

The name of the repository without the .git extension. The name is not case sensitive.

Textparameter
Name, type, BESCHREIBUNG
title string

A name for the key.

key string Erforderlich

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-Antwortstatuscodes für „Create a deploy key“

StatuscodeBESCHREIBUNG
201

Created

422

Validation failed, or the endpoint has been spammed.

Codebeispiele für „Create a deploy key“

Beispiel für eine Anfrage

post/repos/{owner}/{repo}/keys
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/keys \ -d '{"title":"octocat@octomac","key":"ssh-rsa AAA...","read_only":true}'

Response

Status: 201
{ "id": 1, "key": "ssh-rsa AAA...", "url": "https://api.github.com/repos/octocat/Hello-World/keys/1", "title": "octocat@octomac", "verified": true, "created_at": "2014-12-10T15:53:42Z", "read_only": true, "added_by": "octocat", "last_used": "2022-01-10T15:53:42Z" }

Get a deploy key

Differenzierte Zugriffstoken für "Get a deploy key"

Dieser Endpunkt funktioniert mit den folgenden Tokentypen.:

Das Token muss einen der folgenden Berechtigungssätze aufweisen.:

  • administration:read

Parameter für „Get a deploy key“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
owner string Erforderlich

The account owner of the repository. The name is not case sensitive.

repo string Erforderlich

The name of the repository without the .git extension. The name is not case sensitive.

key_id integer Erforderlich

The unique identifier of the key.

HTTP-Antwortstatuscodes für „Get a deploy key“

StatuscodeBESCHREIBUNG
200

OK

404

Resource not found

Codebeispiele für „Get a deploy key“

Beispiel für eine Anfrage

get/repos/{owner}/{repo}/keys/{key_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/keys/KEY_ID

Response

Status: 200
{ "id": 1, "key": "ssh-rsa AAA...", "url": "https://api.github.com/repos/octocat/Hello-World/keys/1", "title": "octocat@octomac", "verified": true, "created_at": "2014-12-10T15:53:42Z", "read_only": true, "added_by": "octocat", "last_used": "2022-01-10T15:53:42Z" }

Delete a deploy key

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

Differenzierte Zugriffstoken für "Delete a deploy key"

Dieser Endpunkt funktioniert mit den folgenden Tokentypen.:

Das Token muss einen der folgenden Berechtigungssätze aufweisen.:

  • administration:write

Parameter für „Delete a deploy key“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
owner string Erforderlich

The account owner of the repository. The name is not case sensitive.

repo string Erforderlich

The name of the repository without the .git extension. The name is not case sensitive.

key_id integer Erforderlich

The unique identifier of the key.

HTTP-Antwortstatuscodes für „Delete a deploy key“

StatuscodeBESCHREIBUNG
204

No Content

Codebeispiele für „Delete a deploy key“

Beispiel für eine Anfrage

delete/repos/{owner}/{repo}/keys/{key_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/keys/KEY_ID

Response

Status: 204