Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.

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

Hi! 

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

Cheers,

Gonchik

Hi Gonchik,

Thanks for replying!

That didn't work either

 

Best,
Marco

I'm having the same issue here.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,886 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you