Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not change permissions while using grafana rest api #11945

Closed
SebastianUA opened this issue May 15, 2018 · 2 comments
Closed

Can not change permissions while using grafana rest api #11945

SebastianUA opened this issue May 15, 2018 · 2 comments

Comments

@SebastianUA
Copy link

Hello here,

Tried to use: http://docs.grafana.org/http_api/admin/ in my python script to change role to admin of grafana.

if be detailed:

PUT /api/admin/users/2/permissions HTTP/1.1
Accept: application/json
Content-Type: application/json

{"isGrafanaAdmin": true} 

Some simple code of my script:

def update_grafana_users(gurl, g_user, g_password, email):
    g_protocol = gurl.split(':')[0]
    g_url = gurl.split('//')[1]

    data_put = {"isGrafanaAdmin": True}

    account_id = search_grafana_user(gurl, g_user, g_password, email)
    if account_id != -1:
        get_data_req = requests.put(
            g_protocol + '://' + g_user + ':' + g_password + '@' + g_url + '/api/admin/users/%s/permissions' % account_id,
            data=data_put)
        pars_json = json.loads(get_data_req.text)
        print(pars_json)

        get_data_req = requests.get(
            g_protocol + '://' + g_user + ':' + g_password + '@' + g_url + '/api/users?perpage=10&page=1')
        pars_json = json.loads(get_data_req.text)
        for user in pars_json:
            if user['email'] == email:
                print(user)
    else:
        print('Unfortunately, I cant find [%s] email in grafana to update role!' % email)
        print('Please, use current EMAIL!')
        exit(0)

    return update_grafana_users

I have got the following text:

$ python3 grafana.py --update --email="test2" --new-password=newPW
{'message': 'User permissions updated'}
{'id': 19, 'name': 'test2', 'login': 'test2', 'email': 'test2', 'isAdmin': False, 'lastSeenAt': '0001-01-01T00:00:00Z', 'lastSeenAtAge': '?'}

If you can see from my output, the role didn't change. So, this key-value is not working at all to me. I tried to change password of the user - it worked properly.

Please help me with my cause issue.
Thanks

@daniellee
Copy link
Contributor

The isGrafanaAdmin property and the isAdmin property are not the same thing. This is not very well explained in the docs for the API.

Grafana Admin is a super admin: http://docs.grafana.org/administration/permissions/#grafana-admin

The isAdmin property is whether the user is an org admin or not: http://docs.grafana.org/administration/permissions/#admin-role

To make the user an org admin, use this endpoint to update the user's role in the specified organization.

@SebastianUA
Copy link
Author

SebastianUA commented May 18, 2018

I know about it. However it's not working with python usage!
I tried to use that think (I would like to add perms as SUPER ADMIN of Grafana) but without any good results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants