2

I'm trying to get a list of all teams on my TFS server(2017) with the following code and the client libraries version is the latest preview.

var teamclient = await Connection.GetClientAsync<TeamHttpClient>();
var teams = await teamclient.GetAllTeamsAsync();

This results in the following exception: API resource location 7a4d9ee9-3433-4347-b47a-7a80f1cf307e is not registered on (tfs link removed for privacy reasons)

Rocco
  • 457
  • 5
  • 23
  • Is this related? https://stackoverflow.com/questions/44299586/api-resource-location-is-not-registered – Yan Sklyarenko May 03 '18 at 13:48
  • There might be two problems. Check my answer here: https://stackoverflow.com/questions/44299586/api-resource-location-is-not-registered/57789384#57789384 – pawciu Sep 04 '19 at 13:29

1 Answers1

3

You could try the following code to list all users:

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

Or you could use the following code to get users in each team:

using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;

namespace GetUser
{
    class Program
    {
        static void Main(string[] args)
        {
            String collectionUri = "http://TFS2017:8080/tfs/defaultcollection";
            VssCredentials creds = new VssClientCredentials();
            creds.Storage = new VssClientCredentialStorage();
            VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
            TeamHttpClient thc = connection.GetClient<TeamHttpClient>();
            List<IdentityRef> irs = thc.GetTeamMembersAsync("TeamProject", "TeamProjectTeam").Result;

            foreach (IdentityRef ir in irs)
            {
                Console.WriteLine(ir.DisplayName);
            }
        }
    }
}

Update:

using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;

namespace GetUser
{
    class Program
    {
        static void Main(string[] args)
        {
                        String collectionUri = "http://TFS2017:8080/tfs/defaultcollection";
        VssCredentials creds = new VssClientCredentials();
        creds.Storage = new VssClientCredentialStorage();
        VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
        TeamHttpClient thc = connection.GetClient<TeamHttpClient>();

        List<WebApiTeam> irs = thc.GetTeamsAsync("AgileProject").Result;

        foreach (WebApiTeam ir in irs)
        {
            Console.WriteLine(ir.Name);
        }

        }
    }
}
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • The user part will be useful. I am however dealing with multiple teams that could be removed an new ones can be added. Therefore I would not want them to be hard coded. Do you think it is because that API doesn't exist inside of TFS 2017? but does in 2018? – Rocco May 04 '18 at 10:25
  • I'm sorry I wrote I wanted a list of users! I actually wanted a list of teams! – Rocco May 04 '18 at 14:28
  • Yeah that would work thanks for your help! I'll just have to manually get a list of the projects first! Just a shame that this company isn't using TFS 2018 yet. One call that gets all users > multiple calls! – Rocco May 07 '18 at 06:51