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

Getting 500 Internal server error when trying to create a branch restriction using API

Bezawada Ashok November 7, 2023

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"
}
}

2 answers

1 accepted

0 votes
Answer accepted
Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2023

Hi @Bezawada Ashok 

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

Bezawada Ashok November 8, 2023

Hi @Saxea _Flowie_ 

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"
}
}

Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2023

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

Bezawada Ashok November 9, 2023

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"
}
}

Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2023

It should be one POST for each entry, instead of sending an array for data.

Bezawada Ashok November 9, 2023

@Saxea _Flowie_ 
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?

Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2023

Fantastic! 

Have a look here

Like Sabine Mayer likes this
0 votes
Bezawada Ashok November 9, 2023

Thanks @Saxea _Flowie_ 
That helped!!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events