Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I get a "malformed value" error when creating a branch permission with API v2.0 ?

Deleted user April 10, 2019

I've been trying to create a branch restriction rule using the API v2.0:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions#post

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?

4 answers

1 accepted

1 vote
Answer accepted
John Tanios
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2019

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.

shawn.roering
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 25, 2019

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.

3 votes
roel.blyweert
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 9, 2020

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.

1 vote
John Tanios
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2019

I'm having the same issue here.

1 vote
Gonchik Tsymzhitov
Community Champion
April 11, 2019

Hi! 

Any lack if you change double-quote into single quote?

Cheers,

Gonchik

Deleted user April 11, 2019

Hi Gonchik,

Thanks for replying!

That didn't work either

 

Best,
Marco

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events