[Solved]Cannot import grafana dashboard via Grafana API

influxdb
grafana

#1

I am trying to import the Grafana dashboard using HTTP API by following Grafana
Grafana Version: 5.1.3 OS -Windows 10
This is what i tried

curl --user admin:admin “http://localhost:3000/api/dashboards/db” -X POST -H “Content-Type:application/json;charset=UTF-8” --data-binary @c:/Users/Mahadev/Desktop/Dashboard.json

and Here is my python code

import requests

headers = {
‘Content-Type’: ‘application/json;charset=UTF-8’,
}

data = open(‘C:/Users/Mahadev/Desktop/Dashboard.json’, ‘rb’).read()
response = requests.post(‘http://admin:admin@localhost:3000/api/dashboards/db’, headers=headers, data=data)
print (response.text)

And output of both is:

[{“fieldNames”:[“Dashboard”],“classification”:“RequiredError”,“message”:“Required”}]

It is asking for root property called dashboard in my json payload. Can anybody suggest me how to use that porperty and what data should i provide.


#2

Thanks I got the answer for my question.
This what I tried and I am able to import the dashboard using grafana import api.

import requests
url='http://admin:admin@localhost:3000/api/dashboards/import'
data='''{
  "dashboard": {
    "annotations": {
          "list":[]
      },
    "editable": true,
    "gnetId": null,
    "graphTooltip": 0,
    "id": null,
    "iteration": 1529322539820,
    "links":[],
    "panels": [{}],
    "schemaVersion": 16,
    "style": "dark",
    "tags": [],
    "templating": {
        "list": []
    },
    "time": {},
    "timepicker": {},
    "timezone": "",
    "title": "name of the dashboard",
    "uid": "uid",
    "version": 1,
    "__inputs": [],
    "__requires": []
  },
  "inputs": [],
  "overwrite": false
}'''
headers={"Content-Type": 'application/json'}
response = requests.post(url, data=data,headers=headers)
print(response)
print(response.status_code)
print (response.text)

#3