Web API to automatically create users and groups

sonarqube

(Kevin Hsu) #1

Our SonarQube version is 6.7.4.
I tried to use Web API to create/add users and groups, just like what we can do via GUI.
I am using a shell script to automate that so everytime when we install a new instance of SonarQube in an environment (such as Dev, QA, etc.) I can automatically create/add some standard users/groups. I know we can do that through GUI. However, we want to automate that through Web API.

Is the following the way to create a user?
https://docs.sonarqube.org/pages/viewpage.action?pageId=2752787#WebService/api/users-CreateaUser

curl -X POST -v -u admin:admin ‘http://localhost:9000/api/users/create?login=myuser&password=mypassword&password_confirmation=mypassword&name=My%20Name&email=myname@email.com

I see that’s an archive. Could you verify if the above is still working? Or please guide me the exact curl I need to do in order to create a user thru Web API?

Thank you,
Kevin Hsu


(Emre Dundar) #2

Hi Kevin,

You can check this page on your Sonar instance for web API guide: http://localhost:9000/web_api/api/users

I tried to run this command and it works:

curl -X POST -v -u admin:admin "http://localhost:9000/api/users/create?login=myuser&password=mypassword&name=myname&email=myname@email.com"


(Julien Lancelot) #3

Hi Kevin,

All web services are listed in your SonarQube instance in http://localhost:9000/web_api

For instance on SonarSource instance, the web service to create a user is https://next.sonarqube.com/sonarqube/web_api/api/users/create

Regards,

Julien Lancelot


(Kevin Hsu) #4

Thank you, Emre and Julien, for your help!