Create a user using api

hello everyone, this topic maybe already has an answer but i can’t find it, i’m trying to create a user (simple viewer) and add it to an organization using the api, but don’t succeed.
i’ve seen this page :
i would like to do it with a curl request but it doesn’t work, can somebody show me the syntax, it would be really helpfull!!

thanks !

You have to use a Grafana Admin user to create users and the authentication has to be Basic Auth. (I updated the docs to be clearer on that point.

curl -XPOST -H "Content-Type: application/json" -d '{
}' http://admin:admin@localhost:3000/api/admin/users

thanks!!! i’ll try this!!!

curl -XPOST -H “Content-Type: application/json” -d ‘{“name”:“User”,“email”:“”,“login”:“user”,“password”:“password”}’ http://admin:admin@localhost:3000/api/admin/users

I tried above one but i got following error
[{“classification”:“DeserializationError”,“message”:“invalid character ‘\’’ looking for beginning of value”},{“fieldNames”:[“Password”],“classification”:“RequiredError”,“message”:“Required”}]

Maybe it is just Discourse that is messing up your curl script but those single and double quotes look strange and they do not work for me in Bash.

You are using “ and ‘ when I think you should be using " and ’

When I switch those out then it works for me.

Thanks ,

Can you share which curl script did you use??

I am new to API’s so i don’t have much knowledge about it.Can you please share me how can I use the api
I referred this -
but i don’t know how to use API’s

I used the curl script in your question. I just changed the single and double quotes to be “straight” quotes instead of the “curly” quotes that you used.

Here is a guide for creating api tokens and dashboards via the api.

Thanks API worked fine with POSTMAN

This works for me

import requests
headers={"Content-Type": 'application/json'}
response =, data=data,headers=headers)
print (response.text)

The following (and variants) works to add a user on Grαfana 5.4.2:

$ curl -X POST -d "name=&username=sam&,approved=true" http://admin:admin@localhost:3000/api/admin/users

However none of the (many) examples that I have seen and followed enable me to set a password through the web API. When I attempt logon through the web, it fails and I first need to set the password through the standard web UI before login with the user created with the curl statement is possible.

Trying to find out what it is doing by going as follows is no dice :wink:

sudo sqlite /var/lib/grafana/grafana.db

Anything I can copy-paste to make this happen?

Many thanks

1 Like

I solved it like this: (ver. 5.4.3)

$ cat bin/graft

> curl -X PUT -d password=$1 http://admin:admin@localhost:3000/api/admin/users/$(curl --silent -X POST -d "email=$\&active=true" http://admin:0logical@localhost:3000/api/admin/users|jq '.id' )/password

run it like this:

$ graft secretpsswd John.Doe

Could not get set home dashboard to work via the API :frowning:
PS Thanks for Grafana :smile: