问题
I'm stumped on how to update team membership through the API. I'm able to add users to projects, through project permissions, but can't update the team membership to show that a user is part of a specific team. How is that best accomplished?
回答1:
The TeamMemberships collection on User is modifiable. Since the question was tagged with C# here is an example of how to do this (assumes wsapi v2.0 and .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);
来源:https://stackoverflow.com/questions/18993417/how-can-i-update-rally-team-membership