Sample - GitHub REST API
POST/repos/{owner}/{repo}/keys

Create a deploy key

Creates a deploy key for a repository. Supply the SSH key contents in key, and use read_only to control whether the key can only read repository contents or can also write to the repository.

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

2 parameters · 3 body fields
ownerstringrequired
The account owner of the repository; the name is not case sensitive.
repostringrequired
The repository name without the `.git` extension; the name is not case sensitive.

Deploy key details for the repository.

titlestringoptional
A name for the key.
keystringrequired
The contents of the key.
read_onlybooleanoptional
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](https://docs.github.com/articles/repository-permission-levels-for-an-organization/)" and "[Permission levels for a user account repository](https://docs.github.com/articles/permission-levels-for-a-user-account-repository/)."

2 status codes
201Returns the created deploy key object, including its identifier, SSH key contents, title, verification status, creation time, access mode, and enabled state.
idintegerrequired
keystringrequired
urlstringrequired
titlestringrequired
verifiedbooleanrequired
created_atstringrequired
read_onlybooleanrequired
added_bystringoptional
last_usedstringoptional
enabledbooleanoptional
422Returned when deploy key validation fails or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 422 is returned when validation fails or the endpoint has been spammed. key is required, and owner and repo must identify the repository that will receive the deploy key. Set read_only to true to restrict the key to read access; otherwise it has read and write access.