Call a REST API

Last Update: 9/26/2016

To call a REST API from your extension, get the client service first, and then use that to call the API.

  1. Get the REST client. In this case, we're getting the work item tracking client.

     VSS.require(["VSS/Service", "TFS/WorkItemTracking/RestClient"], function (VSS_Service, TFS_Wit_WebApi) {
         // Get the REST client
         var witClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
         // ...
     });
    
  2. Call the API (getWorkItems) using the client service (witClient), with a callback that handles results.

     witClient.getWorkItems(/* some work item IDs */ [1,2,3,4], ["System.Title"]).then(
         function(workItems) {
             console.log(JSON.stringify(workItems));
         });
    

Try this next

Display the results of your REST API call in a Grid.