Change the password of users in grafana using python script?

Hi all,

I am trying to change the password that already multiple users exists in the grafana. but i am not able change the password in grafana.
I am pasting my code in the below.

import requests

grafana_url = “http://localhost:3000
username = “”
password = “”

user_id_to_update =

new_password = “123”

update_user_url = f"{grafana_url}/api/admin/users/{user_id_to_update}"

data = {
“password”: new_password

resp = requests.put(update_user_url, json=data, auth=(username, password), verify=False)

if resp.status_code == 200:
print(f"Password updated successfully for user with ID {user_id_to_update}“)
print(f"Failed to update password for user with ID {user_id_to_update}: {resp.text}”)

I am not sure that this code was right or wrong.

As it happens I’ve implemented this too. You haven’t specified headers = {'Content-Type': 'application/json','Accept': 'application/json'}. I don’t know if that’s necessary, but my code works with it in.

I had name, email and login keys in the data dict too. I’m still not sure from Grafana’s docs what name is used for if it’s different to login.

The end point I used was: f'http://{admin_user}:{admin_password}@{network_alias_or_ip_address}:{port}/api/admin/users' instead of the auth arg.

Thank you for suggesting.