1
votes

I'm currently working on a project where I need to POST git tags using the TFS Rest API. I am limited to using the API version 2.0, which has no documentation for how I can POST a tag, however the functionality must be there as the response code does not indicate that a POST is not possible. My request looks something like this.

POST {root_url}/DefaultCollection/{project}/_apis/git/repositories/{repository}/refs?api-version=2.0"
{
   "name": "refs/tags/test",
   "objectId": "{commitId}"
}

The error that I get is as follows:

{ "$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: refUpdates","typeName":"System.Argu mentNullException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","typeKey":"ArgumentNullE xception","errorCode":0,"eventId":0} The remote server returned an error: (400) Bad Request.

I'm not too sure if it's even possible to POST a tag but given the error it should be. Does anyone know how to create a tag using POST or know where I can find documentation for it?

1
POST as in create with an API call? How about this?orhtej2

1 Answers

1
votes

Just noted that the REST API you posted is used to Modify one or more refs but not add a git tag.

I can reproduce your issue when use the REST API you posted above (See below screenshot for your reference).

So, to create a tag you need to use the correct REST API :create annotated tag with the REST API

POST https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}/annotatedTags?api-version={version}

I can create the tag correctly with api-version=3.2-preview.1

eg:

POST http://SERVER:8080/tfs/DefaultCollection/feb1793b-4d91-4be4-8373-02216ec5c36b/_apis/git/repositories/ee76df2b-7c31-484e-ad3a-1a21e6b43cfc/annotatedTags?api-version=3.2-preview.1

Content-Type: application/json

{"name":"3344","message":"test1020","taggedObjectId":"ee26491f1919a9afc9181c00a259bf689afced28"}

UPDATE:

If you are using TFS 2015 or earlier version, then it's not supported, you can use git tag command to do that.

So, if the REST API is the only option, the solution is that you have to upgrade to TFS 2017 or later version.

enter image description here

enter image description here