Create user through API

Grafana version: 4.6.0
Browser: Firefox 62.0.3 (x64)

Hello! I’ve been trying to create a user through the Grafana API, but apparently something very weird is happening ( perhaps because it’s an older version of Grafana? ).
@Edit: I’ve tried with the new version of Grafana, the same problem occurs.
And I’m Using XMLHttpRequest.

If I try to create a user using only the Basic Auth ( default of admin:admin ), the server returns a 401 Unauthorized. But if I have a cookie of an admin user logged in, the server creates the user normally. But in the documentation it’s said that all you need is the Basic Auth of an Admin user.

See pictures attached.


Not seeing any Authorization (basic auth) header in your api call

1 Like

Interesting. For a minute there I thought that the admin:admin@ before the URL was enough to count as BasicAuth.

Using the Authorization: Basic header works as intended. Also, I think it’s worth mentioning on the documentation that if you have a Admin cookie you can create the user through the API as well.

But for my intentions I’ve found a different workaround for this:

You can set the enable_signup to true on Grafana config and make the requests to create a user through the api/user/signup/step2 URL, there’s no need for any admin privilege or header and after the user is created, the browser sets the (created user’s) cookie automatically.

Thanks for the help!