Connect to Grafana with cURL

Use cURL to interact with your Logit.io Grafana instance via the REST API. This is ideal for quick testing, shell scripts, and CI/CD pipelines.

Prerequisites

⚠️
You will need to update any placeholder variables with your Stack and Proxy Auth details.

Authentication

All API requests require authentication using either:

  • Basic Auth Header (recommended) - Pre-encoded Base64 string
  • Username and Password - cURL handles the encoding

Common API Operations

Health Check

Verify your connection and credentials:

curl -XGET -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/health"

Example response:

{
  "commit": "abc1234567",
  "database": "ok",
  "version": "10.0.0"
}

List All Dashboards

Search for all dashboards in your Grafana instance:

curl -XGET -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/search?type=dash-db"

Example response:

[
  {
    "id": 1,
    "uid": "abc123",
    "title": "System Metrics",
    "type": "dash-db",
    "tags": ["metrics", "system"],
    "folderTitle": "General"
  }
]

Get Dashboard by UID

Retrieve a specific dashboard by its UID:

curl -XGET -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/dashboards/uid/<DASHBOARD_UID>"

Export Dashboard to JSON

Export a dashboard and save it to a file (requires jq):

curl -XGET -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/dashboards/uid/<DASHBOARD_UID>" \
  | jq '.dashboard' > my-dashboard.json

Import Dashboard from JSON

Import a dashboard from a JSON file:

First, create an import payload file import-payload.json:

import-payload.json
{
  "dashboard": {
    "title": "My Imported Dashboard",
    "tags": ["imported"],
    "timezone": "browser",
    "panels": [],
    "schemaVersion": 38
  },
  "folderId": 0,
  "overwrite": true
}

Then import it:

curl -XPOST -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  -d @import-payload.json \
  "https://grafana.logit.io/s/@metrics_id/api/dashboards/db"

Example response:

{
  "id": 5,
  "uid": "new-uid-123",
  "url": "/d/new-uid-123/my-imported-dashboard",
  "status": "success",
  "version": 1
}

List Folders

List all folders in your Grafana instance:

curl -XGET -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/folders"

Create Folder

Create a new folder to organize dashboards:

curl -XPOST -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  -d '{"title": "My New Folder"}' \
  "https://grafana.logit.io/s/@metrics_id/api/folders"

Example response:

{
  "id": 2,
  "uid": "folder-uid-123",
  "title": "My New Folder",
  "url": "/dashboards/f/folder-uid-123/my-new-folder"
}

Delete Dashboard

Delete a dashboard by UID:

curl -XDELETE -H "Content-Type: application/json" \
  -H "Authorization: Basic @proxyAuthSetting.basicAuthHeader" \
  "https://grafana.logit.io/s/@metrics_id/api/dashboards/uid/<DASHBOARD_UID>"

Using Username and Password

As an alternative to the Basic Auth header, you can use the -u flag with username and password. However, be aware that inline credentials in command-line arguments can be visible in shell history and process lists.

⚠️

For production use, consider using environment variables or other secure methods to avoid exposing credentials in shell history.

Using Environment Variables (Recommended)

# Set credentials as environment variables
export GRAFANA_USER="@proxyAuthSetting.username"
export GRAFANA_PASS="@proxyAuthSetting.password"
 
# Use environment variables in curl command
curl -XGET -H "Content-Type: application/json" \
  -u "${GRAFANA_USER}:${GRAFANA_PASS}" \
  "https://grafana.logit.io/s/@metrics_id/api/health"

Using Inline Credentials (Not Recommended for Production)

If you must use inline credentials, be aware they will appear in shell history:

curl -XGET -H "Content-Type: application/json" \
  -u "@proxyAuthSetting.username:@proxyAuthSetting.password" \
  "https://grafana.logit.io/s/@metrics_id/api/health"

API Reference

EndpointMethodDescription
/api/healthGETHealth check
/api/searchGETSearch dashboards and folders
/api/dashboards/uid/{uid}GETGet dashboard by UID
/api/dashboards/uid/{uid}DELETEDelete dashboard
/api/dashboards/dbPOSTCreate/update dashboard
/api/foldersGETList folders
/api/foldersPOSTCreate folder
/api/folders/{uid}DELETEDelete folder

Further Reading