没有记录用于将成员添加到项目和团队的 REST API。正如 Hugh 提到的,我们可以使用开发工具跟踪 REST API(在浏览器中按 F12),但是正如我们所见,我们只能在请求 json 正文中使用用户和团队/组 GUID。
Post https://wsicads2019/DefaultCollection/{project}/_api/_identity/AddIdentities?api-version=5.0
Request Body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
对于特定的团队/组,我们可以使用REST API 项目和团队来获取他们的 GUID。对于用户而言,实际上是使用,将用户添加到 Azure DevOps Server 时会自动生成TeamFoundationId
唯一性。TeamFoundationId
我们无法使用外部工具生成 ID。
因此,要使用该 REST API,我们需要获取TeamFoundationId
您想要将其添加到项目/团队的特定用户。
目前,没有 REST API 来列出TeamFoundationId
Azure DevOps Server 2019 中的用户,但是我们可以使用 Client API 获取它:
下面的示例供您参考以获取TeamFoundationId
特定用户的:(它还将导出用户列表及其TeamFoundationId
到userlist.txt
)
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System.Linq;
using System.IO;
namespace Getuserlist
{
class Program
{
static void Main(string[] args)
{
TfsConfigurationServer tcs = new TfsConfigurationServer(new Uri("https://wsicads2019"));
IIdentityManagementService ims = tcs.GetService<IIdentityManagementService>();
TeamFoundationIdentity tfi = ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None);
TeamFoundationIdentity[] ids = ims.ReadIdentities(tfi.Members, MembershipQuery.None, ReadIdentityOptions.None);
using (StreamWriter file = new StreamWriter("userlist.txt"))
foreach (TeamFoundationIdentity id in ids)
{
if (id.Descriptor.IdentityType == "System.Security.Principal.WindowsIdentity" && id.UniqueName == "Domain\\User")
{ Console.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId); }
file.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId);
}
var count = ids.Count(x => ids.Contains(x));
Console.WriteLine(count);
Console.ReadLine();
}
}
}