Getting 500 Internal server error when trying to create a branch restriction using API
Asked by Bezawada Ashok:

From the below API curl request, I am trying to create a restriction for push and restrict merges for a repository   

curl --location '<https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_name}/branch-restrictions>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data '\[ {  
"kind": "push",  
"branch_match_kind": "glob",  
"pattern": "test",  
"users": \[{"username": "{username}"}\]  
},  
{  
"kind": "restrict_merges",  
"branch_match_kind": "glob",  
"pattern": "test" ,  
"users": \[{"username": "{username}"}\]  
}\]'  

And I am getting the below error

{  
"type": "error",  
"error": {  
"message": "Something went wrong",  
"id": "674e26aa0b7b4227b3d7bea36d4bfc9c"  
}  
}


Answers:
author: Saxea _Flowie_
body: Hi [@Bezawada Ashok](/t5/user/viewprofilepage/user-id/5221246)

Instead of username try using uuid e.g.: users: \[{"uuid": "{xxx}"}\]

comments: author: Bezawada Ashok
body: Hi [@Saxea _Flowie_](/t5/user/viewprofilepage/user-id/5230209)   

I tried using uuid too instead of usernames. Still i get the same error   

curl --location '<https://api.bitbucket.org/2.0/repositories/zestmoney/ashok_sandbox/branch-restrictions>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data '\[  
{  
"kind": "push",  
"branch_match_kind": "glob",  
"pattern": "test",  
"users": \[  
{  
"uuid": "730581e7-aed6-4c75-b2cd-32f81cbb9a6d"  
}  
\]  
},  
{  
"kind": "restrict_merges",  
"branch_match_kind": "glob",  
"pattern": "test",  
"users": \[  
{  
"uuid": "730581e7-aed6-4c75-b2cd-32f81cbb9a6d"  
}  
\]  
}  
\]'  

Error:   
{  
"type": "error",  
"error": {  
"message": "Something went wrong",  
"id": "6d61caada38d4ab7922a00068e8bf583"  
}  
}


author: Saxea _Flowie_
body: The uuid need to be around "{...}", so uuid: "{730581e7-aed6-4c75-b2cd-32f81cbb9a6d}"


author: Bezawada Ashok
body: Still i am getting the same error even after making that change  

curl --location '<https://api.bitbucket.org/2.0/repositories/zestmoney/ashok_sandbox/branch-restrictions>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data '\[  
{  
"kind": "push",  
"branch_match_kind": "glob",  
"pattern": "test",  
"users": \[  
{  
"uuid": "{730581e7-aed6-4c75-b2cd-32f81cb9a6d}"  
}  
\]  
},  
{  
"kind": "restrict_merges",  
"branch_match_kind": "glob",  
"pattern": "test",  
"users": \[  
{  
"uuid": "{730581e7-aed6-4c75-b2cd-32f81cb9a6d}"  
}  
\]  
}  
\]'  

Error:  
{  
"type": "error",  
"error": {  
"message": "Something went wrong",  
"id": "7f89a4159a064e8eb8c2b7ef43d5cdb7"  
}  
}


author: Saxea _Flowie_
body: It should be one POST for each entry, instead of sending an array for data.


author: Bezawada Ashok
body: [@Saxea _Flowie_](/t5/user/viewprofilepage/user-id/5230209)   
Yes, it is working if i hit each entry in a separate POST request.   

Also, is there any API which I can use for adding **default reviewers** to a repository?


author: Saxea _Flowie_
body: Fantastic!

Have a look [here](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-default-reviewers-target-username-put)


author: Bezawada Ashok
body: Thanks [@Saxea _Flowie_](/t5/user/viewprofilepage/user-id/5230209)   
That helped!!


Tags: bitbucket-cloud

cloud