# Impossible to add user permission to a grafana dashboard

**URL:** <https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579>\
**Category:** Dashboards\
**Tags:** api\
**Created:** [December 21, 2023, 9:20pm UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579 "2023-12-21T21:20:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurentrioux91](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@laurentrioux91](https://community.grafana.com/u/laurentrioux91)\
**Post date:** [December 21, 2023, 9:20pm UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/1 "2023-12-21T21:20:58Z")

</div>

Hello Grafana community,

I’m using Grafana 10.2 version on linux and I trying to create a python program to authorize a user to view a dashboard. Seem simple, but facing difficulties since many days.

Today, I can import a dashboard via the HTTP API and I can create the user, but impossible to add permission to the user the view the imported dashboard.

I follow the API reference guide and today the program finish with success but all permissions are removed except the Admin.

see the pictures of the permissions, before and after my program.

 ![Before_modif_permissions](https://us1.discourse-cdn.com/grafana/original/3X/6/0/605edd9c69b8f72e9ffd78e932a1878055caf50d.png)

 ![after_modif_permissions](https://us1.discourse-cdn.com/grafana/original/3X/2/5/250d090450d1afb8d5fa656a75ae56e58fef1384.png)

here below my program:

```auto
from requests.auth import HTTPBasicAuth
import json
import subprocess

grafana_url_api = 'http://192.168.YYY.XXX:3000/api'

auth = ('admin', 'zzzzzzzz')

grafana_token = "XXXXXXXXXXXXXXXXXXXXXXXX"

router = "util7"

url= grafana_url_api + "/users/lookup?loginOrEmail=" + router

response = requests.get(url, auth=auth)

if response.status_code == 200:
   myuser_data = response.json()
   user_uid = myuser_data.get("id")
   print(f"User UID for user {router}: {user_uid}")
else:
   print(f"Failed to retrieve user UID. Status Code: {response.status_code}, Response: {response.text}")

 *#provide permission to user to dashboard*
myheader = {
      'Authorization': f"Bearer {grafana_token}",
      'Content-Type': 'application/json',
      'Accept': 'application/json',
}

url = grafana_url_api + f'/dashboards/uid/{router}-R/permissions'
print(url) 

  #Get the current dashboard permissions*
response = requests.get(url, headers=myheader)

if response.status_code == 200:
   dashboard_data = response.json()
   print(dashboard_data)
 
   new_user_entry = {
      'userId': user_uid,
      'permission': 1,
   }

   update_response = requests.post(url, headers=myheader, json=new_user_entry)

   if update_response.status_code == 200:
       print(f'Permission for {router} updated successfully to Viewer')
   else:
       print(f'Failed to update permission: {update_response.text}')
else:
      print(f'Failed to fetch dashboard data: {response.text}')

```

Do you have any glue to solve the issue?

I really need help on this. Thanks all of you.

---

<div class="post-metadata">

**Author:** ![sowdenraymond](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sowdenraymond/32/38541_2.png) [@sowdenraymond](https://community.grafana.com/u/sowdenraymond)\
**Post date:** [December 22, 2023, 7:14am UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/2 "2023-12-22T07:14:13Z")

</div>

Hi,

I see your json payload only includes the new permissions you wish to set, the documentation is pretty clear that if you leave any of the existing permissions out of your payload, they will be removed…

> **[Dashboard Permissions HTTP API | Grafana documentation](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard_permissions/)**
>
> Grafana Dashboard Permissions HTTP API

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/8/3/835338eff806339b5551b876b22ae88c276282b9.png)

---

<div class="post-metadata">

**Author:** ![laurentrioux91](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@laurentrioux91](https://community.grafana.com/u/laurentrioux91)\
**Post date:** [December 22, 2023, 8:35pm UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/3 "2023-12-22T20:35:07Z")

</div>

Yes, I understand that the viewer and editor role have been removed because I have not put them in the json (it is what I want indeed). But my user is not added.

Even, when I add the “admin” user I got the same result: The user is not added to the permissions to the dashboard.

Cheers,

Laurent

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [December 22, 2023, 8:51pm UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/4 "2023-12-22T20:51:49Z")

</div>

General recommendation: use UI and set permission via UI + watch API calls in the browser console and then just replicate them in your code. Print also API response status code, not only response text in your code. And of course read them.

You complain that your code is not working, but you didn’t show your response status codes, text when it is not working.

And please format code, texts when you are posting them here.

---

<div class="post-metadata">

**Author:** ![laurentrioux91](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@laurentrioux91](https://community.grafana.com/u/laurentrioux91)\
**Post date:** [December 22, 2023, 9:26pm UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/5 "2023-12-22T21:26:49Z")

</div>

here the message from the API response:

 ![message](https://us1.discourse-cdn.com/grafana/original/3X/d/0/d0e97388319151ade5cfec57e92aa07943a3182f.png)

Status Code: 200, Response: {“message”:“Dashboard permissions updated”}  
{‘message’: ‘Dashboard permissions updated’}

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [December 23, 2023, 1:37am UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/6 "2023-12-23T01:37:56Z")

</div>

So API request is correct. Payload is probably wrong. As I mentioned: use browser console and construct right payload.

---

<div class="post-metadata">

**Author:** ![laurentrioux91](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@laurentrioux91](https://community.grafana.com/u/laurentrioux91)\
**Post date:** [December 23, 2023, 9:42am UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/7 "2023-12-23T09:42:00Z")

</div>

Thank you for your help, the idea to use the browser console was a great idea.

now it is working so I give the solution for others:

auth3 = (‘xxxx’, ‘yyyyy’)

mytext = {“permission”:“View”}

url = grafana\_url\_api + f’/access-control/dashboards/{dash\_uuid}/users/{user\_uid}’

response = requests.post(url, auth=auth3, json=mytext)  
print(f"Status Code: {response.status\_code}, Response: {response.text}")

in fact, my previous url and json were wrong. So you need the user uid and the dashboard uid to update the permissions

Solved !!

---

<div class="post-metadata">

**Author:** ![isaqueprofeta](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/isaqueprofeta/32/38142_2.png) [@isaqueprofeta](https://community.grafana.com/u/isaqueprofeta)\
**Post date:** [October 20, 2024, 1:38am UTC](https://community.grafana.com/t/impossible-to-add-user-permission-to-a-grafana-dashboard/110579/11 "2024-10-20T01:38:35Z")

</div>


