I've been trying to create a branch restriction rule using the API v2.0:
I'm using python, and this is what my params and request look like:
data = {
"branch_match_kind" : "glob",
"kind" : "require_approvals_to_merge",
"type" : "branchrestriction",
"pattern" : branch,
"value" : str(br_approvals),
"users" : [],
"groups" : []
}
r = requests.post('https://api.bitbucket.org/2.0/repositories/' + user + '/' + repo_slug + '/branch-restrictions', auth=HTTPBasicAuth(user, password), data=data)
It contemplates every mandatory field, including "value", which is why I don't understand why I keep getting the following error:
400
b'{"type": "error", "error": {"message": "malformed value"}}'
Can anyone shed some light on this?
I just figured it out.
Use
r = requests.post('https://api.bitbucket.org/2.0/repositories/' + user + '/' + repo_slug + '/branch-restrictions', auth=HTTPBasicAuth(user, password), json=data)
Apparently, when you pass a dict through data, it converts everything to a string, while the API is expecting an int.
Also, make sure value is an int. Don't convert it to a string.
I'm unable to get the api to work. I cannot get past the malformed value error. Below is the output from "json.dumps(data)", except that I added new-lines for readibility.
POST /2.0/repositories/my-owner/my-repo/branch-restrictions HTTP/1.1
{
"kind": "require_approvals_to_merge",
"branch_match_kind": "glob",
"pattern": "master",
"type": "branchrestriction",
"users": [],
"groups": [],
"value": 2
}
If I enable debugging on the http client, it shows content length as 156 bytes. If the value was getting converted to a string (i.e. getting quoted), then the content length would need to be 158 characters. So I don't believe that is my issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same problem here. I tried with both curl and python and none of them are working. Some debugging using the developer tools in the bitbucket GUI pointed me to some internal API call that gets done with the same data parameters as mine, but it does work in the bitbucket GUI. I think this is a bug in this API endpoint.
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.
Hi!
Any lack if you change double-quote into single quote?
Cheers,
Gonchik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gonchik,
Thanks for replying!
That didn't work either
Best,
Marco
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.