Hi all, I’m relatively new to using the Grafana APIs so would appreciate any help people can give. I am currently trying to incorporate a Grafana installation & setup in to auto-deployment scripts I am writing - the stages of this auto-deployment essentially being:
- Download Grafana ZIP from the web & unzip (Done)
- Edit defaults.ini file to correspond to that of the target deployment (Done)
- Start Grafana Server on target machine (Done)
- Create a new InfluxDB data source - Work In Progress
- Import several pre-built Grafana dashboards (stored locally as JSON) (Later)
For the penultimate step, as this is an auto-deployment needs to be done using the Data source HTTP API. Now, my understanding from here-on is not great, so I could be wrong. I understand that to access the Data source HTTP API, I need an API Key which can be created using the Authorisation HTTP API. I understand that the Authorisation API can be accessed using an existing API Key (which won’t exist), or using BasicAuth, because initially no API Key will exist. That is my understanding of the processes that need to occur, but if I have missed anything or have misunderstood, any advice is appreciated.
The HTTP Request I am doing to attempt to obtain an API Key is as follows:
POST http://grafana.staged-by-discourse.com/api/auth/keys HTTP/1.1 (community.grafana.com is where Grafana Server is running)
Accept: application/json
Content-Type: application/json
Host: community.grafana.com
{
“name”: “TEST”,
“role”: “Admin”,
“secondsToLive”: 86400
}
I have taken this from https://grafana.com/docs/grafana/latest/http_api/auth/#create-api-key and omitted the Authorization field from the header, instead setting “Basic Auth” as the authorisation type in Postman (I’m using Postman to test communication with APIs). I have entered the default username & password (admin/admin) in to the Authorization tab in Postman too.
When I send the request, I get a response code 422: Unprocessable Entity, with the following:
[
{
“fieldNames”: [
“Name”
],
“classification”: “RequiredError”,
“message”: “Required”
},
{
“fieldNames”: [
“Role”
],
“classification”: “RequiredError”,
“message”: “Required”
}
]
I’m not too sure what RequiredError means, though I assume it is referring to missing values somewhere. This is despite entering values for these fields in the initial request, so I’m not too sure what’s going on.
As before, any help people can provide - whether suggestions to fix what I’m doing or alternative ways of achieving what I’m trying to, are much appreciated.
Currently using Grafana 6.7.4