1
votes

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?

2
The end of the working query has "?ids=1,2,3" which are parameter for the query. The non working query has "/3" which is think is wrong. It need to look similar to first query with a question mark and then the parameters.jdweng
as per documentation the format is differentTheProvost
Every server is different..We cannot help without the documentation. Best to contact the vendor support. The format of the request is bad and each server request are different.jdweng

2 Answers

1
votes

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!

0
votes

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.