🏏 450 million fans watched the last IPL. What is 'Cricket Scale' for SREs? Know More

Jan 31st, β€˜23/Changelog

Access to Embedded Grafana via Last9 API

You can access the Embedded Grafana using Last9 API and manage your Grafana Dashboards

Last week we released the embedded Grafana, which can be used to explore metrics coming into your Levitate clusters.

This week we are happy to announce the API access to the embedded Grafana so that you can create and manage the Grafana dashboards with just the Last9 API.

Last9 API uses OAuth2 Bearer tokens for read, write and delete operations.

The tokens can be generated from the API Access page for the first time.

Last9 API Access

Once on the API access page, you can generate the tokens by clicking on GENERATE TOKENS.

Generate Last9 API Tokens
Generate Last9 API Tokens

Last9 API supports three types of tokens:

  • Read tokens - used for GET endpoints.
  • Write tokens - used for the POST and PUT endpoints.
  • Delete tokens - used for DELETE endpoints.
Last9 API Tokens
Last9 API Tokens

Each token is also accompanied by the refresh token used to regenerate the access token when it expires.

Base URL

The base URL for accessing embedded Grafana is as follows.

https://app.last9.io/api/gp/v1/organizations/<org_slug>/

The org_slug is the same as the following:

Org identifier
Org identifier

The actual Grafana endpoints will follow the base URL. E.g., the get dashboard by uid the endpoint will look like this:

https://app.last9.io/api/gp/v1/organizations/<org_slug>/api/dashboards/uid/:uid

Here is a list of all Grafana API endpoints that can be used.

πŸ’‘
Note that embedded Grafana access is enabled on first use from the Last9 Explore tab. Visit the Explore tab once before accessing the API.

Accessing the Embedded Grafana via API

To access the list of dashboards in my embedded Grafana, generate a READ API token from the API access page and perform the following cURL:

curl --location --request GET 'https://app.last9.io/api/gp/v1/organizations/<org_slug>/api/search' \\
--header 'X-LAST9-API-TOKEN: Bearer <READ_TOKEN>'

This will return the following response:

[
    {
        "id": 2,
        "uid": "s8WDB0hVz",
        "title": "levitate",
        "uri": "db/levitate",
        "url": "/api/gp/dashboards/f/s8WDB0hVz/levitate",
        "slug": "",
        "type": "dash-folder",
        "tags": [],
        "isStarred": false,
        "sortMeta": 0
    }
]

For any operations that involve writing operations, use the WRITE token.

curl --location --request POST 'https://app.last9.io/api/gp/v1/organizations/<org_slug>/api/dashboards/db' \\
--header 'X-LAST9-API-TOKEN: Bearer <WRITE_TOKEN>' \\
--header 'Content-Type: application/json' \\
--data-raw '{
  "dashboard": {
    "id": null,
    "uid": null,
    "title": "Production Overview",
    "tags": [ "templated" ],
    "timezone": "browser",
    "schemaVersion": 16,
    "version": 0,
    "refresh": "25s"
  },
  "message": "Made changes to dashboards",
  "overwrite": false
}'

With the valid WRITE token, the dashboard will get created with the following response:

{
    "id": 14,
    "slug": "production-overview",
    "status": "success",
    "uid": "D4AoXJTVz",
    "url": "/api/gp/d/D4AoXJTVz/production-overview",
    "version": 1
}

Access control

All users have the editor role in the embedded Grafana, so the same ACL applies to the editor role in Grafana.

Last9

Cloud Native Monitoring

Β© 2024 β€” Last9, Inc
All rights reserved.

Last9 on DiscordLast9 on LinkedInLast9 on TwitterLast9 on YouTubeLast9 on Peerlist
Last9 Levitate is an AWS Qualified Software Partner
Last9 Levitate is a Cloud Native Computing Foundation Silver Member
Last9 Levitate is Soc2 Type 2 certified

SOC2 Type 2 certified.
Contact us for the report.