broAhmed
broAhmed

Reputation: 192

Is there a TFS extension SDK API or REST API call to get all users from TFS 2017?

I have a TFS extension that needs to get a list of all users in TFS 2017. Is there an API call for this? The closest thing I've been able to find is the CoreHttpClient.getTeamMembers() REST client call. But I'm looking for something that returns a list of all user identities.

Google searches have yielded some results for older versions of TFS that don't appear applicable to TFS 2017.

Note 1: this is for an on-site hosted TFS instance, not VSTS.

Note 2: I'm looking for a way to call this API from the frontend JavaScript code of the TFS extension.

Thanks!

UPDATE 06/29/2017: See Patrick's comment in his answer. Apparently there's no REST API that's callable from the TFS extension frontend at the moment.

Upvotes: 2

Views: 1350

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51183

There is no Rest API could do this for now. You have to use old client API with ReadIdentities method. This also works on TFS2017. Sample code:

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("url"));
tfs.EnsureAuthenticated();

IGroupSecurityService gss = tfs.GetService<IGroupSecurityService>();

Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);

Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);

foreach (Identity user in UserId)
{
    Console.WriteLine(user.AccountName);
    Console.WriteLine(user.DisplayName);
}

More details please refer How do I get list of all users in TFS 2013 and there is also many others in google.

It's using .NET client libraries for TFS, you could use those method by importing the nuget package into your Visual Studio projects. This is also work with TFS2017.

Upvotes: 3

Related Questions