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...
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
Great Theodora, that was very helpful! thanks.
is it possible to include this information also on the webhook events request body too?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.