0

I am trying to create a new user in Azure DevOps using Rest API C# and by debugging the code I am not seeing any error and the user information were showing correct after I get result of the created new user. My issue is that the user is NOT saved after the application is completed and I do not see the user in Azure DevOps. When I check the status of the task it is WaitingForActivation.

Here is the code I am using and please advise what is wrong:

        VssConnection connection = new VssConnection(new Uri(uri), new VssBasicCredential(string.Empty, personalAccessToken));
        GraphHttpClient graphClient = connection.GetClient<GraphHttpClient>();
        GraphUserMailAddressCreationContext usr = new GraphUserMailAddressCreationContext();
        usr.MailAddress = "someuser@somedomain.com";
        GraphUser u = graphClient.CreateUserAsync(usr).Result;
Nick
  • 780
  • 2
  • 13
  • 33

1 Answers1

1

Creating a New User in Azure DevOps using Rest API

According to your code segment, it seems you are adding a user via Graph. But add a user via Graph does not give them access to the account, the user has to be materialized and added to the appropriate projects, groups etc.

To add a user, I suggest you can use another API User Entitlements - Update User Entitlement with following request body:

[
  {"from":"",
    "op":0,
      "path":"/projectEntitlements",
        "value":{"projectRef":{"id":"<MyProjectID>"},"group":{"groupType":3}}

  }
]

You can check my another thread for some more details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks for your response. As I have never used User Entitlements before, do you have an idea how to use it in C# code please? – Nick Aug 16 '19 at 13:08
  • @Nick, Since you are using Rest API C# , you do not need to be particularly familiar with User Entitlements. Please check this demo: https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1 – Leo Liu Aug 19 '19 at 09:55