How to set the password when we create an user with an API call?

Hi,
I’m actually trying to create user with the API and I figured out that we can’t set the password in the call ?

POST /api/org/users HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
“role”: “Admin”,
“loginOrEmail”: “admin”
}

So how can the user login without password ? Is it a default password ? Should I make an other call to change the password of this user ?

Thank you for the help

The org api can only add existing users or create invites, not create new users.

To create a new user you need to use the admin api:
http://docs.grafana.org/http_api/admin/#global-users

1 Like

Hi @torkel,
and to get all the users, I can only do GET grafana_url/api/org/users right ?

Or I’m missing a method somewhere ?

and I get the error “403 permission denied” with the call to add the user, maybe you can figure out what is wrong in my JS call ?

    HTTP.call("POST", "http://grafana.staged-by-discourse.com/api/admin/users", {
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'Authorization': APIKEY_ADMIN,
                },
                data: {
                    "name":name,
                    "email":"",
                    "login":name,
                    "password":"userpassword",
                }
            }

where APIKEY_ADMIN is something like Bearer xxxxx

you cannot use an api key here, as you need a user with grafana admin permissions. Will have to use basic auth with a username/password that has Grafana Server Admin permission set.

Perfect :slight_smile:

And it’s right for the part where I want to get all the users ?