How to create the first admin user through rest api

I have an application to integrate with mattermost. But the mattermost server is not accessible publicly. Since I cannot open the mattermost application on the browser, I was finding a solution to create the first admin user through rest API call or if there is some preconfiguration to do so.

1 Like

Hello, @tsadkan

The easiest way to do this is to create user via API and then promote the user to system admin via mattermost roles system_admin CLI.

However, you mentioned this:

What is the error that you are getting when you are trying to reach the Mattermost server via UI? What is the output of running echo | telnet <mattermost_url> 443 if the instance is set up via TLS? I am concerned that the API will just fail if you cannot even reach to Mattermost in the first place.

Since the Mattermost Server access is an issue, may I know if you have also reached out to the existing System Administrator(s) to assist with this process as it will be a lot faster if they can do it from their end?

Hello @ahmaddanial,
It is due to my architecture. Which doesn’t allow Mattemost server to be publicly accessible. We are planning to access the mattermost server through an other server as a proxy.

I know I can create a user through the api but by default the open user creation is not allowed. To update this “Enable open server” config, we can use the rest API but the request needs authorization which I don’t have at first.

So, my question is how to create the first admin through rest API request, If that makes sense.

@tsadkan, from the sounds of it, you will have to create the first user via the CLI, having direct access to the Mattermost server itself. Creating the “first” user through the REST API requires enable sign-up with email, enable user creation, and an open server in order to use the REST API (or, equivalently, the web browser).

1 Like