Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Is there a REST API or other mechanism that I can use to programmatically add a public key to a specific repository in BitBucket? The end goal would be to add a public key to BitBucket for either a user or a specific repo without having to manually copy and paste the key into the GUI
There is a REST endpoint that you can use:
To add an SSH key to the current user
{
"text": "ssh-rsa AAAAB3... me@127.0.0.1",
"label": "me@127.0.0.1"
}
to <bitbucket-baseurl>/rest/ssh/latest/keys
(label is optional)
To add an SSH key to a repository
{
"key": {
"text": "ssh-rsa AAAAB3... me@127.0.0.1",
"label": "some-label"
},
"permission": "REPO_WRITE"
}
to <bitbucket-baseurl>/rest/ssh/latest/projects/<project-key>/repos/<repo-slug>
You can find all SSH endpoints in the Bitbucket Server Docs under the REST documentation for SSH keys under
Perfect! This is exactly what I needed - thanks very much for sending that over. I'll give it a try and let you know if I have any issues. Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the documentation website for the REST documentation for SSH keys down? I'm attempting to access it and am getting the below error. I've also included the URL (accessed by clicking the link that you provided) I'm attempting to access should that prove useful. I also attempted to access the documentation for my version of bitbucket (4.9.1) and also got a 404 but with a different output. If this API and its documentation is substantially different from the current version, can you please provide a link to that as well? Thanks in advance for your time and attention to this matter.
https://docs.atlassian.com/DAC/rest/bitbucket-server/5.6.2/bitbucket-ssh-rest.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I am trying to add the key to the repository with REPO_WRITE permission, but it looks like it ignores permission and forcibly add the key with REPO_READ permission.
Should the user have some special permissions to add the key with REPO_WRITE permission?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just for future reference: the REST documentation for SSH keys is not down, but the URL has changed a bit. Here is the currently working URL:
https://docs.atlassian.com/bitbucket-server/rest/5.6.2/bitbucket-ssh-rest.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would this also work on the api.bitbucket.org hosted repo's?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bitbucket Server or Bitbucket Cloud?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.