1

I am pulling a file from on premise TFS source control using the Rest API. I can't find on premise specific documentation, but it seems to be very close to version 4.1 of the Azure Get Item call. According to this documentaiton, it should return a TfvcItem object which has a lot of metadata including the version. However, when I make the call it only returns the file contents (the content field of the documentation's TfvcItem).

How do I get the current version of the file?
I need the version when I check itin with create changeset. I don't need it for any other reason, so if you know another way to check in an edited file that would help.

Don Chambers
  • 3,798
  • 9
  • 33
  • 74

2 Answers2

1

Instead of using Get Item API, some related REST APIs are not documented. For these REST APIs we can use tools such as Fiddler or directly press F12 - network in Chrome to track them.

You should use below API to fetch latest changeset version of a file:

post   https://dev.azure.com/{organizationname}/{Projectname}/_api/_versioncontrol/history?__v=5 

For body:

{"repositoryId":"","searchCriteria":"{\"itemPath\":\"$/MyFirstProject/Main/1.txt\",\"itemVersion\":\"T\",\"top\":50}"}

itemPath is your server path of the file.

From the response, you will get the version info such as "version": "139", instead of the file content.

Not sure your detail version of TFS, I was using Azure DevOps Service for an example. There maybe some difference for different TFS version. You could track the detail API on your own side.

More detail info kindly take a look at this question: VSTS Release API Documentation

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
1

Had the same issue. You can get item metadata by specifying "scopePath" URI parameter, instead of "path". Microsoft example in API documentation seems incorrect, as it indeed returns only item content: https://learn.microsoft.com/en-us/rest/api/azure/devops/tfvc/items/get?view=azure-devops-rest-6.0#get-item-metadata-and/or-content-for-a-single-item.

Oleksiy
  • 11
  • 1