Call a REST API

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

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

Note

Looking for Azure DevOps REST APIs? See the latest Azure DevOps REST API reference.

For information about .NET client libraries, see .NET client libraries for Azure DevOps.

Client services

You can find the full list of available REST clients and their references here.

Call an API

You'll have to add the scope "scopes": ["vso.work"], to your vss-extension.json to use the work item tracking client.

  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));
        });
    

Next steps

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