我对如何通过API更新团队成员资格感到困惑。我可以通过项目权限将用户添加到项目中,但无法更新团队成员资格以显示用户是特定团队的一部分。如何最好地完成?
答案 0 :(得分:0)
User上的TeamMemberships集合是可修改的。由于问题是用C#标记的,因此这是一个如何执行此操作的示例(假设wsapi v2.0和.net rest toolkit 2.0):
//Get the current team memberships for a user
var user = restApi.GetByReference("/user/12345", "TeamMemberships");
Request teamMemberRequest = new Request(user["TeamMemberships"]);
List<DynamicJsonObject> teams = new List<DynamicJsonObject>(restApi.Query(teamMemberRequest).Results.Cast<DynamicJsonObject>());
//Add the new team (project)
DynamicJsonObject newTeam = new DynamicJsonObject();
newTeam["_ref"] = "/project/23456";
teams.Add(newTeam);
//Update the user
DynamicJsonObject toUpdate = new DynamicJsonObject();
toUpdate["TeamMemberships"] = teams;
restApi.Update(user["_ref"], toUpdate);