Is it possible to know through an API if a branch is main branch?

Nimrod Golan November 16, 2023

Is it possible to know through an API if a branch is set as a main branch?

wasn't able to see anything about it. only thing was on the UI itself where when it lists the branches, each branch entity has the 'ismainbranch' property, but on the official API documentations there is nothing... 

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 17, 2023

Hi Nimrod,

You can use the following API endpoint to get a repository's main branch:

You can request a partial response and only get the main branch with a call like this:

curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo?fields=mainbranch.name' \
--header 'Authorization: Bearer access-token' \
--header 'Accept: application/json'

 

It is also possible to get this info with the endpoint that gets a branch:

If you don't request a partial response you'll need to use field discovery:

curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo/refs/branches/somebranch?fields=*.*.*.*' \
--header 'Authorization: Bearer access_token' \
--header 'Accept: application/json'

You can also request a partial response as follows:

curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/workspace-id/repo/refs/branches/somebranch?fields=target.repository.mainbranch.name' \
--header 'Authorization: Bearer access_token' \
--header 'Accept: application/json'

Please feel free to reach out if you have any questions!

Kind regards,
Theodora

Nimrod Golan November 18, 2023

Great Theodora, that was very helpful! thanks.

is it possible to include this information also on the webhook events request body too? 

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 20, 2023

You are very welcome, Nimrod!

This field is not included in events payloads. We have a feature request to return this field in the Repository entity of webhooks event payloads:

I would suggest adding your vote to that feature request (by selecting the Vote for this issue link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

Implementation of features is done as per our policy here and any updates will be posted in the feature request.

Kind regards,
Theodora

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events