How to create user and api token during installation process?


I am teaching and I use AWS EC2 service.

During VMs instantiations, I scripted Sonar installation. Like that when the environment is deployed, students have access to a Sonar server. The main purpose is to avoid that students make mistakes if they deploy Sonar server themselves.

But I would like to create a user and an API key by script. I know that’s possible but with an administrator api key.

So in my script installing Sonar server, I need to be able to access admin api key or to be able to create a user with an api key without knowing the admin api key.

Is it possible ?

PS: I faced with the same problem for Gitlab installation, but Gitlab has a tool, gitlab-rails runner, that allow to create a user without using the REST API. So this tool solved my problem: I create a user with an api key with this tool.



HI Bernard,

Sorry, but I’m not following what you want to do.

You want to

  • Script the creation of a SonarQube instance for each student - doable
  • In each instance, create a user - doable
  • In each instance, you want to create an API key - ??? do you mean a user token?

To create the user, you’ll use the credentials of the default admin. You may need to make the first step changing the password. I’m sure you’ve probably noticed that you’re required to change them on first login. Then you can use basic access to create your users and tokens.

The best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

You may also find this guide helpful.


Thanks for your answer Ann.

My goal is to script the deployement of a CI/CD stack ready to be used using Cloud Formation.

Then to use Maven to build a “system” and to send coverage reports to Sonar and to send reports to sonar i need an user token. But the best would be to not change the pom file.

So for that I need to be able to script Sonar deployment (done), and in the same script to create a user and a user token.

As explained I faced to same probblem with Gitlab but with Gitlab there is a tool to create user with token without knowing the admin account.

I hoppe that I explained what i want to do.



Hi Bernard,

You can do that with the Web API, as I described above.


Hi Ann,

I am not sure because I have to realize manual actions : change the admin password and generate the token.

This post Feedback of Cloud formation and JMeter use to teach system tests provides more context about my question.



Hi Bernard.

Again, perform the actions you want to script manually in the UI. And use your browser’s developer tools to see what API calls are used to accomplish those steps. Then you can script those calls.