How to interact with deploy-keys via the bitbucket api

Sebastiaan Van Hoecke January 11, 2019

Hi,

 

I am trying create deploy-keys for a certain repository but it keeps giving me this response:

<Response [400]>
{"key": [{"message": "This field is required.", "code": "required"}]}

 

There is no reference in the documentation about this: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/deploy-keys#post

 

my setup:

 

NOTE: the ssh-key is the same as in the docs so no harm in showing, it is for testing.

import requests
import json

user = "******"
password = "*******"

repo = "******"

auth = requests.auth.HTTPBasicAuth(user, password)
host = "https://api.bitbucket.org"
headers = {"content-type": "application/json"}
payload = {
"code": 1,
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAK/b1cHHDr/TEV1JGQl+WjCwStKG6Bhrv0rFpEsYlyTBm1fzN0VOJJYn4ZOPCPJwqse6fGbXntEs+BbXiptR+++HycVgl65TMR0b5ul5AgwrVdZdT7qjCOCgaSV74/9xlHDK8oqgGnfA7ZoBBU+qpVyaloSjBdJfLtPY/xqj4yHnXKYzrtn/uFc4Kp9Tb7PUg9Io3qohSTGJGVHnsVblq/rToJG7L5xIo0OxK0SJSQ5vuId93ZuFZrCNMXj8JDHZeSEtjJzpRCBEXHxpOPhAcbm4MzULgkFHhAVgp4JbkrT99/wpvZ7r9AdkTg7HGqL3rlaDrEcWfL7Lu6TnhBdq5 mleu@C02W454JHTD8",
"label": "mydeploykey",
}

post = "/2.0/repositories/wegroupwolves/{repo}/deploy-keys".format(repo=repo)
r = requests.post(host + post, auth=auth, data=json.dumps(payload))
print(r, r.text 

 

1 answer

1 accepted

0 votes
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 14, 2019

Hello Sebastiaan and welcome to the Community!

We researched why this was causing an issue and why you're being presented with this required field. We found the following within your header should resolve the issue:

r = requests.post(host + post, auth=auth, data=json.dumps(payload))

To

r = requests.post(host + post, auth=auth, headers=headers, data=json.dumps(payload))

 Please let us know if this helps to resolve your required field error.

Regards,
Stephen Sifers

Sebastiaan Van Hoecke January 15, 2019

Oh my ... What a mistake.

 

Thank you very much for replying!

Like Stephen Sifers likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events