Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

BitBucket API 2.0 tag information not showing in commit REST API endoint

carlodesutter
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 26, 2019

Hi,

I'm trying to make use of the following endpoint: 

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D

to fetch a specific commit object and ideally its linked tag(s).

I noticed in the doc url above that the following information should be included in the response:

A ref object, representing a branch or tag in a repository.

For some reason, the responses I'm getting back do not include this piece of information. The same goes for the https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/tags#get endpoint where I'm fetching tags, the commit information is not included either.

After spending quite some time going through the docs as well doing some searches I'm not able to see what the reason for this would be. I'm having the impression that the response data works with some type of base type, so perhaps I need to send in some extra parameter that enables this extra piece of data.

Let me know if you require more information from my end,

Regards

Carlo

 

1 answer

1 accepted

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 26, 2019

Hi @carlodesutter,

The first endpoint, /commit/<node>, doesn't return tags. Not sure why the documentation has that bit, we'll look into that.

The latter endpoint you mentioned is the right one to use. If you request /refs/tags without any parameters, you'll get a paginated list of all tags in your repository. Each item in the list will have commit hash in target.hash element. Example.

To find tag for specific commit(s) you can make use of BBQL, e.g. a query like target.hash="<commit_hash>" would do the trick for a single commit. Note that you need to URL-encode it. Example that fetches tags for two commits.

Lastly, you can ask for less or more data by passing fields parameter:

  • Excluding some fields can help reducing the time Bitbucket needs to process your request and saving a bit of network traffic. Example that excludes tagger and author fields.
  • Adding some fields is useful when you need some extra bit which is not returned by default. It is usually either because it might be expensive or because that element was considered less relevant. Example that also fetches language field for the repository element for each tag.
  • You can combine exclusions and additions. However, sometimes it's more useful to just ask for specific fields instead. Example that gets only commit hash, date along with pagination info.

Let me know if this helps.

Cheers,
Daniil

carlodesutter
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 26, 2019

Hi Daniil,

 

It looks like 

https://api.bitbucket.org/2.0/repositories/{repo}/refs/tags?q=target.hash={sha1} is doing the trick

Thanks for your feedback

Kind regards

Carlo

Like Daniil Penkin likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events