You can use the Dashboard API to list dashboards, create a dashboard, download the json for a dashboard, update a dashboard and modify a dashboard.
Show a dashboard
Use the below query to show the JSON for the dashboard you created in the last exercise.
https://api.newrelic.com/v2/dashboards/<dashboard-id>.json
Provide header X-Api-Key: {{apiKey}}
Create a dashboard
Use the below query to update the table element from being 2 widgets wide, to being 3 widgets wide. Save it as something new.
https://api.newrelic.com/v2/dashboards.json
Provide header X-Api-Key: {{apiKey}} ; Content-Type: application/json
Body:
{
"dashboard": {
"id": 1010834,
"title": "GS: insights workshop",
"description": null,
"icon": "bar-chart",
"created_at": "2019-10-14T13:43:57Z",
"updated_at": "2019-10-14T13:43:57Z",
"visibility": "all",
"editable": "editable_by_all",
"ui_url": "https://insights.newrelic.com/accounts/1147177/dashboards/1010834",
"api_url": "https://api.newrelic.com/v2/dashboards/1010834",
"owner_email": "gspenceruk@gmail.com",
"metadata": {
"version": 1
},
"widgets": [
{
"visualization": "billboard",
"layout": {
"width": 1,
"height": 1,
"row": 1,
"column": 1
},
"widget_id": 12786823,
"account_id": 1147177,
"data": [
{
"nrql": "from PageView SELECT count(session) since 30 minutes ago"
}
],
"presentation": {
"title": "Page Views in the last 30 minutes",
"notes": null,
"threshold": {
"red": null,
"yellow": null
}
}
},
{
"visualization": "facet_bar_chart",
"layout": {
"width": 1,
"height": 1,
"row": 1,
"column": 2
},
"widget_id": 12786824,
"account_id": 1147177,
"data": [
{
"nrql": "FROM PageView SELECT count(session) SINCE 24 hours ago FACET city LIMIT 10"
}
],
"presentation": {
"title": "Cities with the most traffic last 24 hours",
"notes": null,
"drilldown_dashboard_id": 1010769
}
},
{
"visualization": "billboard",
"layout": {
"width": 1,
"height": 1,
"row": 1,
"column": 3
},
"widget_id": 12786825,
"account_id": 1147177,
"data": [
{
"nrql": "FROM Transaction SELECT average(databaseDuration) as 'DB Duration (ms)' SINCE 1 hour ago"
}
],
"presentation": {
"title": "Average DB Duration (ms) for last hour",
"notes": null,
"threshold": {
"red": 0.5,
"yellow": 0.05
}
}
},
{
"visualization": "facet_table",
"layout": {
"width": 3,
"height": 1,
"row": 2,
"column": 1
},
"widget_id": 12786826,
"account_id": 1147177,
"data": [
{
"nrql": "SELECT average(duration), count(*) FROM Transaction FACET name SINCE 1 hour ago LIMIT 5"
}
],
"presentation": {
"title": "Five slowest transactions for the last hour",
"notes": null,
"drilldown_dashboard_id": null
}
}
],
"filter": {
"event_types": [
"PageView"
],
"attributes": [
"city"
]
}
}
}