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

Create tag using REST api for bitbucket server

tbielejeski July 20, 2020

I was following the API docs https://docs.atlassian.com/bitbucket-server/rest/6.10.0/bitbucket-rest.html?_ga=2.33858657.1166200213.1595259633-444055661.1594387875#idp347. but it seems that is not working for Private Enterprise Bitbucket Servers. 

 

What I found that for Enterprise, the API access is formed in the way

 

{my-private-bibucket-server}//rest/api/latest/projects/{project-id}/repos/{repo-id}/

 

I was able to fetch tags by using 

 

GET {my-private-bitbucket-server}/rest/api/latest/projects/{project-id}/repos/{repo-id}/tags 

 

However, when I try to do a POST 

 

post {my-private-bitbucket-server}/rest/api/latest/projects/{project-id}/repos/{repo-id}/tags 

 

with the body 
{
"name" : "test-tag",
"
startPoint" : {
     "hash" : "<some hash value>"
  }
}

it doesn't work

I am using powershell 

1 answer

1 accepted

0 votes
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 21, 2020

Hi there!

I'd love to help out here but am interested in what error you're getting. Fairly regularly when people try to switch from a GET to a POST (at least in Postman), the Content-Type header doesn't get set. If it isn't there, Bitbucket will respond with a 415 Unsupported Media Type error.

image.png

If you're using the Invoke-RestMethod cmdlet in Powershell, adding the ContentType flag should patch up error 415:

-ContentType 'application/json'

 

Now if you're getting a 500 Internal Server Error for your request, I think it's because the structure isn't quite what Bitbucket Server is looking for. Try this body instead:

{
"name" : "test-tag",
"startPoint" : "<some hash value>"
}
The start point parameter is expecting a single value instead of an array. And less nesting means it's more readable too!
Cheers,
Daniel
tbielejeski July 22, 2020

I did get it working - Ended up being you can not have any spaces in the tag name.

Would be nice to have better error handling, Or have that info in the documentation  

孟行 July 21, 2021

Hello,I was following the API docs https://docs.atlassian.com/bitbucket-server/rest/6.10.0/bitbucket-rest.html?_ga=2.33858657.1166200213.1595259633-444055661.1594387875#idp347 to create tag.

I was able to fetch tags by using GET in postman

image.png

 

But when I try to do POST, I get 500 Internal Server Error

image.png

 

I was confused

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events