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 = "[email protected]";
        GraphUser u = graphClient.CreateUserAsync(usr).Result;
0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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, Since you are using Rest API C# , you do not need to be particularly familiar with User Entitlements. Please check this demo: learn.microsoft.com/en-us/rest/api/azure/devops/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.