Hello all,
Grafana API , how to create datasource & dashboards in specific ORG, the API call missing that , or there any sequence of doing that?
Regards,
Oleg
Hello all,
Grafana API , how to create datasource & dashboards in specific ORG, the API call missing that , or there any sequence of doing that?
Regards,
Oleg
The org is taken from the api key/bearer token. An api key is organization specific so to create data sources and dashboards for an org, create an API key for that org.
Hi, thanks for the reply, it works. But, what could be the sequence of the API calls to script the process the of creation the ORG default datasource & default dashboards in this ORG.
something like:
Thank you for your help.
If I understand your question correctly, you want to know how to create an org and an API Key (token) via the API before you have a token?
Two options:
An example of using basic auth to access the api (admin user and password is admin):
curl http://admin:admin@community.grafana.com/api/orgs
Hi Daniel,
thanks, yes, I am actually using the basic auth to create an ORG.
I performed the quick test . and the token has been created in the Main.Org instead of Test.
So the question , how i can create the token via API inside the chosen Org. ,
I was thinking that I have to do the next:
However, you may suggest more optimal solution.
Regards,
Oleg
Ok, this was a bit complicated. Going to put this in a guide on the docs site.
curl -X POST -H "Content-Type: application/json" -d '{"name":"apiorg"}' http://admin:admin@community.grafana.com/api/orgs
Optional step. If the org is already created and step 3 fails then first add your Admin user to the org:
curl -X POST -H "Content-Type: application/json" -d '{"loginOrEmail":"admin", "role": "Admin"}' http://admin:admin@community.grafana.com/api/orgs/<org id of new org>/users
Switch the org context for the Admin user to the new org:
curl -X POST http://admin:admin@community.grafana.com/api/user/using/<id of new org>
curl -X POST -H "Content-Type: application/json" -d '{"name":"apikeycurl", "role": "Admin"}' http://admin:admin@community.grafana.com/api/auth/keys
Here is a first draft of a guide for creating a Token and adding a dashboard:
Hi Daniel,
thanks , i will check after my vacation!
Have a nice weekend.
Regards,
Oleg
Thank you for creating this document. I came looking for exactly this information.
I wonder whether you could expand on how the token is intended to be used. For example, is this like a session token, which should be re-created every time my application connects to the API? Or is this something permanent which I should save in my application and re-use each time? Does is expire after a certain time? Should I explicitly delete it when my session ends?
It is not a temporary token and is meant to be reused. You should treat the token/api key like a password and save it in a safe place.
It does not expire but you can revoke it via the Grafana GUI if you ever need to limit access (user has left the company or the token gets lost)
Sorry, I’ve been distracted for a bit and didn’t reply sooner, but thank you for the answer; this helps.
I’ve got two grafana instances. I connect to them thru java code.
First one has external administrator (I don’t control this instance). I go thru steps 1, 3 and 4. 1st (returns organization id= 120) and 3rd are ok with response code 200. 4th step returns also ok, but the key is assigned to organization with id=1. Tried also to use step number 2, but it returns 409 (I belive it’s ok, the admin was assigned by default to this organization).
Second instance is local on my desktop. If there, the script returns correct key for new organization (doing steps 1,3,4).
Any suggestions what could go wrong? Any configuration issue? What can make that switching org context for Admin returns with 200, but it’s still sam org with id = 1.
Please mention id number with in " " it will work
Hey, everyone!
I found a really simpler solution for that, just use X-Grafana-Org-Id header in your requests.
This header helps to specify organization for dashboard creation API, as well as for datasource creation API without additional requests to change the current user.