Get API key from Grafana API

Hi all,

i want to use Ansible to deploy Grafana, Grafana Reporter (https://github.com/IzakMarais/reporter) and a couple of dashboards.

In those dashboards, i want to add a PDF exporter button through a Grafana link. In the URL, i need the API key value.

With the following curl command i have the key’s id, name and role but not the value…

curl http://admin:admin@localhost:3000/api/auth/keys
[{"id":1,"name":"grafana-reporter","role":"Viewer"}]

The key value is displayed only when i create the a new key:

curl 'http://admin:admin@localhost:3000/api/auth/keys' -XPOST -H 'Content-Type: application/json' -d '{"role":"Viewer","name":"grafana-reporter2"}'
{"name":"grafana-reporter2","key":"eyJrIjoieE5TQ210TG9YMXd5U2U2Q1dwZnB5ZkdZVFR4OHJNS1ciLCJuIjoiZ3JhZmFuYS1yZXBvcnRlcjIiLCJpZCI6MX0="}

Is there a way to get the key ?

Hi @nicolargo,

This is a security feature to prevent unintended leaking of sensitive token information. There is no way to read an API token after its creation. It is assumed the administrator will copy it in a password manager at the time the token is created if retention is needed.

If you need to update an API token, the procedure is to delete the old one and create a new one.

Ok, i copy that.

Thanks !