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

Marco Aurélio Alano Godinho I'm New Here Apr 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?

3 answers

1 accepted

1 vote
Answer accepted
John Tanios Sunday

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.

0 votes
Gonchik Tsymzhitov Community Leader Apr 11, 2019

Hi! 

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

Cheers,

Gonchik

Marco Aurélio Alano Godinho I'm New Here Apr 11, 2019

Hi Gonchik,

Thanks for replying!

That didn't work either

 

Best,
Marco

0 votes
John Tanios Sunday

I'm having the same issue here.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,971 views 1 19
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