简体   繁体   中英

TFS 2018 API: Can access workitems but not workitem API end point

I created a middleware app that will pull work item data from TFS.

I was able to do this using the workitems end point.

http://sampleserver:8080/tfs/sampleproject/_apis/wit/wiql?api-version=4.0/workitems?ids=1,2,3

Now, I also need to get the work item links per work item. Per docu I would need to access the workitem with expand items. But unfortunately, work item end point does not seem to work.

http://sampleserver:8080/tfs/sampleproject/_apis/wit/wiql?api-version=4.0/workitem/3

Am I missing something here?

According to your description, looks like you just want the URL of created WorkItem, so that anyone when click on URL, created Work Item will be Open.

https://tfsurl:8080/tfs/DefaultCollection/PatrickProject/_workitems/edit/172/

The URL should be above format and here DefaultCollection is the collection name and the PatrickProject is the project name. I used this url and got rid of the id '172' in this case and use the ID of newly created work item. This would return the URL to go to the work item HTML page.

So it's a fixed format, if you have Newly Created WorkItem ID and collection name , project name, you just need to follow above format and change the last value of work item ID. That's it , ignore of which work item type you created.

If you want do this with code, do not use Rest API, you need to use client API, sample snippet:

var tfsURI = new Uri("http://test:8080/tfs");
var networkCredential1 = new NetworkCredential("test", "test!");

    ICredentials credential = (ICredentials)networkCredential1;
    Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(credential);
    VssCredentials vssCredentials = new VssCredentials(winCred);

    using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(tfsURI, vssCredentials))
    {
        collection.EnsureAuthenticated();
        TswaClientHyperlinkService hyperlinkService = 
           collection.GetService<TswaClientHyperlinkService>();
        String TFSurl = hyperlinkService.GetWorkItemEditorUrl(17648).ToString(); //17648 WorkItem ID
    }

Hope this Helps!

To get specific work item information you need to use the Get Workitem API call so try http://sampleserver:8080/tfs/sampleproject/_apis/wit/workitems/3?api-version=4.0 instead.

You can also use this http://sampleserver:8080/tfs/sampleproject/_apis/wit/workitems/3?$expand=Links&api-version=4.0 and this will return the work with Id of 3 and all it's links (parent, attached files, changetset, etc.)

Notice that the api-version=4.0 with change depending on the version of TFS/Service you are using and should always be the last string in the REST call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM