如何以编程方式在VSTS团队中添加成员? [英] How to add member in VSTS team programmatically?

查看:93
本文介绍了如何以编程方式在VSTS团队中添加成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式添加特定团队(在特定项目中)的用户/成员(已经拥有VSTS帐户).在门户网站上,我们总是可以做到这一点.但是,我正在寻找一些REST服务,该服务将为我做同样的事情.

I want to add user / member (who has already VSTS account) in a particular team (Under a particular project) programmatically. From portal we can always do the same. But, I am looking for some REST service that will do the same for me.

在以下文档来自Microsoft,我们获得了与团队相关的几个api.但是它没有提供任何与如何将现有VSTS帐户持有人添加到团队中"相关的任何信息

In the below documentation is from Microsoft, we get several api related to the team. But it does not provide anything related to 'how do I add existing VSTS account holder to a team'

https://www.visualstudio.com/en -us/docs/integrate/api/tfs/teams

谢谢.

推荐答案

选项1:REST API(暂时不可用)

目前,尚无此类REST API可以将成员添加到团队项目中. 但是有一个用户声音

Option 1: REST API (not available for now)

For now, there is no such REST API to add members to a team project. But there has an user voice add rest api for adding members to a team which suggest to add this feature for REST API, you can vote and follow up.

一旦REST API可用,您就可以以编程方式使用REST API将成员添加到团队中.

Once the REST API is available, you can use REST API programmatically to add member to a team.

您还可以在注释部分的用户语音下引用相关代码(将成员添加到默认团队的示例):

You can also refer the related code under the user voice in comments part (an example for adding members to default team):

public Task<TeamProject> GetProjectAsync(string projectId) 
{ 
var projectClient = this.Connection.GetClient<ProjectHttpClient>();

return projectClient.GetProject(projectId); 
} 
public async Task GrantProjectAccessAsync(string projectId, string email) 
{ 
var project = await this.GetProjectAsync(projectId);

var client = this.Connection.GetClient<IdentityHttpClient>(); 
var identities = await client.ReadIdentitiesAsync(Microsoft.VisualStudio.Services.Identity.IdentitySearchFilter.MailAddress, email); 
if (!identities.Any() || identities.Count > 1) 
{ 
throw new InvalidOperationException("User not found or could not get an exact match based on email"); 
} 
var userIdentity = identities.Single(); 
var groupIdentity = await client.ReadIdentityAsync(project.DefaultTeam.Id); 

await client.AddMemberToGroupAsync( 
groupIdentity.Descriptor, 
userIdentity.Id 
); 
}

要为另一个团队添加成员,可以使用

To add members for another team, you can use teamClient.GetTeamsAsync method to get teams for the project, and then get the team id by matching the given team name.

这篇关于如何以编程方式在VSTS团队中添加成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆