Auto Create Admin User and Avoid Welcome Page

I would like to utilize the API to automatically create a user and make it an admin, bypassing the “Congratulations, You Installed Discourse Page”

My existing approach:

rake api_key:get -> api_key

Terrific. I have an API key that works.

I then create a new user:

POST https://discourse.example.com/users
content-type: application/json
Accept: application/json
Api-Key: dsafdsfdafkeyhere
Api-Username: system

{
"name": "John Admin",
"email": "my-admin@example.com",
"password": "supersecretp@ssword!",
"username": "my-admin",
"active": true,
"approved": true
}

Results in a 200 with confirmation the user is created. Now I want to add that user to the admin group:

PUT https://discourse.example.com/groups/1/members.json
content-type: application/json
Accept: application/json
Api-Key: d9adsfadsfdsakjfkdsf83
Api-Username: system

{
"usernames": "my-admin"
}

And I receive a 403 forbidden:

{
  "errors": [
    "You are not permitted to view the requested resource."
  ],
  "error_type": "invalid_access"
}

Any ideas why I can’t add my newly created user to the admin group?

The only workaround I have is to use rake admin:create which is not ideal because of the interactive prompt…which requires me to modify the RB to take environmental variables as input for the prompt variables. rake admin:create is also not ideal because it generates strange usernames based on email.

Admin is an automatic group. You do not make someone admin by adding them to that group. Someone is added to the group by making them admin.

1 Like

How can I make them admin via the API?