Get tags in a Stash commit using REST API

Chris I'm New Here Dec 05, 2017

When I use the REST API to get the details for a commit:


I get a json file that has the commit author, message, time stamp... but NO TAGS! I can see in stash that this commit does in fact have tags and I need this information.

Ok, so I tried to use the TAGS API:


Nope, doesn't work. The only thing that you can do with tags is to add a string filter and ordering which is completely useless to me.

Is there something I'm missing? Is there a way to do this?

1 answer

0 vote

Hi Chris,


The way tags are retrieved is by using the  /rest/api/latest/projects/<project>/repos/<repo>/tags REST API.


For each tag this returns a JSON representation in this format:



This is where the commit hash is available.


If you are looking to find the tags on a commit, you should get all the tags for the repositories and then retrieve the one that matched the hash.


I see that Bitbucket Server uses a different approach to retrieve the tags for a commit by using the following request:


And then passing the commit hash in the payload.


However, this is an internal only API and should not be used in any program or script because it could be removed at any time.


It would be useful to understand what you are trying to achieve here.




Chris I'm New Here Dec 18, 2017

Thanks for your response. So what you are saying is that in order to get the tags associated with a specific commit hash I have to download this json info for ALL the tags in the repo and match the hashcode one by one myself? I was hoping there would be an alternative as we have quite a large repo with a LOT of tags. Also it looks like it limits the number of tags you can get this info for and I couldn't see how I could iterate through to get the next lot using the existing API.

Anyway, what I was trying to do was get the Jira issues added from an older tag to a newer tag (but first I needed to know what tags the given commits had as I parsed through them).

As an aside, I also had a go at creating Bamboo releases to work in parallel with our own build process and use the feature in there to get the Jira issues, but I had problems getting it to work due to the repo size and in any case had hell on Earth trying to get the releases to be automatically labelled with the tag for the commit (I gave up).

In the end I mostly bypassed the REST API altogether and wrote a script to parse my locally checked out copy of the repo and pattern match for anything that looks like a Jira commit code in the comments. Then later I call the Jira REST API to get more info on the Jira issue corresponding to that Jira code.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,739 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you