TeamCity REST API: Add user to group? Follow
Could someone please provide an example of what the REST API call would be used to add a user to a userGroup?
Either type of example would work for our use case:
- Add a user to an existing group during the process of creating the user.
- Add an existing user to an existing group.
There was a previous post alluding to the fact that the first option was possible however it did not provide an example of how it was possible.
Please sign in to leave a comment.
Hi Michael,
The users element has the "groups" property. It includes the groups it belongs to. If you pass the groups when creating the user with the mandatory "KEY" parameter the user will automatically be added to the groups.
Adding an existing user to a group, it should be simple. You can post to the "app/rest/users/<user locator>/groups" to add a user to a group. The endpoint will accept a "group" object, which will be an instance of the groups returned by requesting a GET to the same endpoint.
I'm having to assign a user to a group programmatically and as I was doing my research, I came across this thread. I understand the URL to use and POST as HTTP method but I'm not sure about "group" object. So I would need to pass the "group" object as body the to POST request right? I'm guessing it's some kind of JSON data but I'm not sure how to form it. Could you please help me out on this one? Is there any example I could take a look at?
You'll need the group key for the target group. You can find your group keys here: http://TEAMCITY_SERVER/httpAuth/app/rest/userGroups
Below is an example using curl:
Hello, Eric. Thank you very much for your help.
I was able to successfully add an existing user to an existing group with a few caveats.
After that, all is good.
Again, thank you very much for your help! :)
Hi,
is there similar way to
how to remove a user from a group?
Sure, you can remove a user from a group with REST API using something like this: