2

I am trying as follows:

SSHKEY=`cat ~/.ssh/id_rsa.pub`
curl -u username:password -X POST -H "Content-Type: application/json" -d '{"key": "$SSHKEY", "label": "someLabel"}' https://api.bitbucket.org/2.0/users/username/ssh-keys

But it is giving:

{"type": "error", "error": {"fields": {"key": ["That SSH key is invalid."]}, "message": "key: That SSH key is invalid."}}

Any idea on how to send this ssh key to bitbucket using api?

1 Answer 1

1

Ok, I made it work using a python 3 script.

#!/usr/bin/python3
import os
import requests, json

url = "https://api.bitbucket.org/2.0/users/userName/ssh-keys"

key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
print(key)

payload = {
        "key": key, 
        "label": "testSSHKey"
       }

header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} 

response_decoded_json = requests.post(url, auth=requests.auth.HTTPBasicAuth('userName', 'password'), data=payload, headers=header)
response_json = response_decoded_json.json()

print(response_json)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.