ReferenceGrafana Cloud API

Grafana Cloud API

The Grafana Cloud API is sometimes referred to as the Grafana.com API or the Gcom API. It is a work in progress, however the following calls and paths on this page are static and approved for general use. If you hear of other paths and calls, know that they are subject to change and not generally maintained for user consumption.

Authentication

Generate an API token in the Grafana.com user portal at https://grafana.com/orgs/<org_slug>/api-keys. Make sure it has the Admin role.

Requests to the API are authenticated using the Authorization header:

Authorization: Bearer <grafana.com API token>

API keys

List API keys

GET https://grafana.com/api/orgs/<org_slug>/api-keys

Create API key

POST https://grafana.com/api/orgs/<org_slug>/api-keys

Body

  • name (string) – API key name.
  • role (string) – Permission level of API key. One of Viewer, Editor, Admin, or MetricsPublisher.

Delete API key

DELETE https://grafana.com/api/orgs/<org_slug>/api-keys/<api key name>

Stacks

Note: Grafana Cloud Free includes 1 stack and Grafana Cloud Pro includes up to 3 stacks. Reach out to us about Grafana Cloud Advanced if you would like to add additional stacks to your account.

List stacks

GET https://grafana.com/api/orgs/<org_slug>/instances

Create stack

Note: This POST request accepts lowercase characters only.

POST https://grafana.com/api/instances

Body

  • name (string) – Name of stack. Conventionally matches the URL of the instance. For example, <stack_slug>.grafana.net.
  • slug (string) – Subdomain that the Grafana instance will be available at. For example, if you set the slug to <stack_slug>, the instance will be available at https://<stack_slug>.grafana.net.
  • url (string, optional) – If you use a custom domain for the instance, you must provide it here. For example, “https://grafana.yourdoman.io”.

Note: For the custom domain, you must set up a CNAME record that points to <stack_slug>.grafana.net before you can specify the domain.

  • region (string, optional) — Choose a region for your stack. For example, you can specify the United States (us) or Europe (eu).

    Use the GET /api/stack-regions endpoint to see a list of regions to choose from. For more information, see List regions.

    If you don’t specify a region, the default is us.

Delete stack

DELETE https://grafana.com/api/instances/<stack_slug>

Restart Grafana

POST https://grafana.com/api/instances/<stack_slug>/restart

Create Hosted Grafana instance API keys

POST https://grafana.com/api/instances/<stack_slug>/api/auth/keys

This creates API keys specific to use for managing your hosted Grafana instance. This is different from Grafana Cloud API keys created for Grafana Cloud operations.

This endpoint requires the Admin role. See the Grafana docs for more details.

Body

  • name (string) – Name of the API key.
  • role (string) – Access level/Grafana role for the key. Can be one of the following values: Viewer, Editor, or Admin.
  • secondsToLive (number, optional) – Key expiration in seconds. If it is a positive number an expiration date for the key is set. The key will never expire if it is null, zero, or is omitted completely (unless api_key_max_seconds_to_live configuration option is set).

List data sources

GET https://grafana.com/api/instances/<stack_slug>/datasources

Grafana plugins

The API allows managing plugins installed on your hosted Grafana instances.

You can discover plugins in the Grafana Plugins Directory.

List plugins installed on an instance

GET https://grafana.com/api/instances/<stack_slug>/plugins

Add a plugin to instance

POST https://grafana.com/api/instances/<stack_slug>/plugins

Body

  • plugin (string) – Name of the plugin, e.g. grafana-github-datasource.
  • version (string, optional) – Version of the plugin to install. Defaults to latest.

Get installed plugin info

GET https://grafana.com/api/instances/<stack_slug>/plugins/<plugin>

Update installed plugin version

POST https://grafana.com/api/instances/<stack_slug>/plugins/<plugin>

Body

  • version (string) – New plugin version.

Delete an installed plugin

DELETE https://grafana.com/api/instances/<stack_slug>/plugins/<plugin>

Regions

List regions

Use the following call to retrieve a list of regions to specify when you create a stack.

GET https://grafana.com/api/stack-regions

Access policies and tokens

Note: The Access Policies and Tokens API endpoints are early access features. This feature is under active development.

This API specification describes endpoints used to manage the new-generation resources for authentication and authorization.

Access policies and tokens use access policy, token, scope, realm, and labelselector resources. For more information about these resources, refer to the Grafana Cloud Acccess Policies documentation. 

All API requests must specify a token in the request’s Authorization header.

You may use a legacy API key obtained from https://grafana.com/orgs/{org}/api-keys or a token created via this API.

Paginated endpoints optionally accept both pageSize and pageCursor query parameters. If pageCursor is not provided or empty, the first page will be requested. The next page’s URL can be obtained from the current page’s metadata.pagination.nextPage property. If that field is null, you’ve reached the last page and there are no records left.

Create an access policy

Create an access policy with the POST method.

POST http://www.grafana.com/api/v1/accesspolicies

Parameters

NameDescription
regionRequired. String. Region where the API is deployed. Generally where the stack is deployed.

Request body

Example request:

{
  "name": "stack-readers",
  "displayName": "Stack Readers",
  "scopes": [
    "metrics:read",
    "logs:read",
    "traces:read",
    "alerts:read"
  ],
  "realms": [
    {
      "type": "stack",
      "identifier": "123",
      "labelPolicies": [
        {
          "selector": "{env != \"dev\"}"
        }
      ]
    }
  ]
}

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "orgId": "1",
  "name": "stack-readers",
  "displayName": "Stack Readers",
  "scopes": [
    "metrics:read",
    "logs:read",
    "traces:read",
    "alerts:read"
  ],
  "realms": [
    {
      "type": "stack",
      "identifier": "123",
      "labelPolicies": [
        {
          "selector": "{env != \"dev\"}"
        }
      ]
    }
  ],
  "createdAt": "2022-06-08T20:07:21.223Z",
  "updatedAt": "2022-06-08T20:07:21.223Z"
}
CodeDescription
400Bad request
401API token is missing or invalid.
409Conflict

List access policies

List specified access policies with the GET method.

GET http://www.grafana.com/api/v1/accesspolicies

Parameters

NameDescription
nameOptional. Query. Name of the access policy to filter by.
realmTypeOptional. String. Query. Available values are org and stack.
realmIdentifierRequires realmType. Optional. String($string). Identifier of the realm.
pageSizeOptional. String. The number of records to be returned per page. The default value is 500; the maximum value is 500.
pageCursorOptional. String. Query. A cursor used for paging through the results. The first page will be fetched when not provided.
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "items": [
    {
      "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
      "orgId": "1",
      "name": "stack-readers",
      "displayName": "Stack Readers",
      "scopes": [
        "metrics:read",
        "logs:read",
        "traces:read",
        "alerts:read"
      ],
      "realms": [
        {
          "type": "stack",
          "identifier": "123",
          "labelPolicies": [
            {
              "selector": "{env != \"dev\"}"
            }
          ]
        }
      ],
      "createdAt": "2022-06-08T16:47:46.151Z",
      "updatedAt": "2022-06-08T16:47:46.151Z"
    }
  ],
  "metadata": {
    "pagination": {
      "pageSize": 500,
      "pageCursor": "ZDMyYzZhODktZjU1ZC00NGViLWJmYWEtMTEyYmE2NTFlNDJifDIwMjItMDQtMTFUMTI6NTQ6MDBa",
      "nextPage": "/v1/accesspolicies?pageCursor=ZDMyYzZhODktZjU1ZC00NGViLWJmYWEtMTEyYmE2NTFlNDJifDIwMjItMDQtMTFUMTI6NTQ6MDBa"
    }
  }
}
CodeDescription
400Bad request
401API token is missing or invalid.

List one access policy

List one access policy with the GET method.

GET http://www.grafana.com/api/v1/accesspolicies/{accessPolicyID}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
accessPolicyIdRequired. String ($uuid). Path. ID of the access policy.

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "orgId": "1",
  "name": "stack-readers",
  "displayName": "Stack Readers",
  "scopes": [
    "metrics:read",
    "logs:read",
    "traces:read",
    "alerts:read"
  ],
  "realms": [
    {
      "type": "stack",
      "identifier": "123",
      "labelPolicies": [
        {
          "selector": "{env != \"dev\"}"
        }
      ]
    }
  ],
  "createdAt": "2022-06-08T21:06:27.853Z",
  "updatedAt": "2022-06-08T21:06:27.853Z"
}
CodeDescription
400Bad request
401API token is missing or invalid.

Update an access policy

Update an existing access policy with the POST method.

POST http://www.grafana.com/api/v1/accesspolicies/{accessPolicyId}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
accessPolicyIdRequired. String (UUID). Path. ID of the access policy.

Request body

The request body specifies the revised access policy.

Example request:

{
  "displayName": "Stack Readers",
  "scopes": [
    "metrics:read",
    "logs:read",
    "traces:read",
    "alerts:read"
  ],
  "realms": [
    {
      "type": "stack",
      "identifier": "123",
      "labelPolicies": [
        {
          "selector": "{env != \"dev\"}"
        }
      ]
    }
  ]
}

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "orgId": "1",
  "name": "stack-readers",
  "displayName": "Stack Readers",
  "scopes": [
    "metrics:read",
    "logs:read",
    "traces:read",
    "alerts:read"
  ],
  "realms": [
    {
      "type": "stack",
      "identifier": "123",
      "labelPolicies": [
        {
          "selector": "{env != \"dev\"}"
        }
      ]
    }
  ],
  "createdAt": "2022-06-08T21:10:37.011Z",
  "updatedAt": "2022-06-08T21:10:37.011Z"
}
CodeDescription
400Bad request
401API token is missing or invalid.

Delete an access policy

Remove an access policy with the DELETE method.

DELETE http://www.grafana.com/api/v1/accesspolicies/{accessPolicyId}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
accessPolicyIdRequired. String (UUID). Path. ID of the access policy.

Responses

The following responses may be returned.

CodeDescription
204Access policy deleted successfully.
400Bad request
401API token is missing or invalid

Create a token

Create a token with the POST method.

POST http://www.grafana.com/api/v1/tokens

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.

Request body

The request body contains details about the token being created.

Example request:

{
  "accessPolicyId": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "name": "mytoken",
  "displayName": "My Token",
  "expiresAt": "2022-06-08T22:05:46.958Z"
}

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "accessPolicyId": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "name": "mytoken",
  "displayName": "My Token",
  "expiresAt": "2022-06-08T22:05:46.959Z",
  "firstUsedAt": "2022-06-08T22:05:46.959Z",
  "createdAt": "2022-06-08T22:05:46.959Z",
  "updatedAt": "2022-06-08T22:05:46.959Z",
  "token": "glc_eyJrIjoiZjI0YzZkNGEwZDBmZmZjMmUzNTU2ODcxMmY0ZWZlNTQ1NTljMDFjOCIsIm4iOiJteXRva2VuIiwiaWQiOjF9"
}
CodeDescription
400Bad request
401API token is missing or invalid
409Conflict

List a set of tokens

List a set of tokens with the GET method.

GET http://www.grafana.com/api/v1/tokens

Parameters

NameDescription
accessPolicyIdOptional. Query. ID of the access policy to filter by.
accessPolicyNameOptional. Query. Name of the access policy to filter by.
accessPolicyRealmTypeOptional. String. Query. Type of the access policy realm. Available values are org and stack.
accessPolicyRealmIdentifierOptional. String ($string). Query. Identifier of the access policy realm. Requires accessPolicyRealmType.
nameOptional. String. Query. Name of the Token to filter by.
expiresBeforeOptional. String. Query. Time (in ISO8601 UTC format) to filter tokens that have expiresAt set before the given time.
expiresAfterOptional. String. Query. Time (in ISO8601 UTC format) to filter tokens that have expiresAt set after te given time.
pageSizeOptional. String. Query. The number of records to be returned per page. Default value is 500; the maximum value is 500.
pageCursorOptional. String. Query. A cursor used for paging through the results. The first page will be fetched when not provided.
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "items": [
    {
      "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
      "accessPolicyId": "c45485b6-8321-4cf2-bcec-12006df755ff",
      "name": "mytoken",
      "displayName": "My Token",
      "expiresAt": "2022-06-08T22:11:05.614Z",
      "firstUsedAt": "2022-06-08T22:11:05.614Z",
      "createdAt": "2022-06-08T22:11:05.614Z",
      "updatedAt": "2022-06-08T22:11:05.614Z"
    }
  ],
  "metadata": {
    "pagination": {
      "pageSize": 500,
      "pageCursor": "ZDMyYzZhODktZjU1ZC00NGViLWJmYWEtMTEyYmE2NTFlNDJifDIwMjItMDQtMTFUMTI6NTQ6MDBa",
      "nextPage": "/v1/accesspolicies?pageCursor=ZDMyYzZhODktZjU1ZC00NGViLWJmYWEtMTEyYmE2NTFlNDJifDIwMjItMDQtMTFUMTI6NTQ6MDBa"
    }
  }
}
CodeDescription
400Bad request
401API token is missing or invalid

List a single token

List a specified token with the GET method.

GET http://www.grafana.com/api/v1/tokens/{tokenId}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
tokenIdRequired. String (UUID). Path. ID of the Token.

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "accessPolicyId": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "name": "mytoken",
  "displayName": "My Token",
  "expiresAt": "2022-06-09T04:31:23.559Z",
  "firstUsedAt": "2022-06-09T04:31:23.559Z",
  "createdAt": "2022-06-09T04:31:23.559Z",
  "updatedAt": "2022-06-09T04:31:23.559Z"
}
CodeDescription
400Bad request
401API token is missing or invalid

Update a token

Update a specified token with the POST method.

POST http://www.grafana.com/api/v1/tokens/{tokenId}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
tokenIdRequired. String (UUID). Path. ID of the Token.

Request body

The request body contains the updated values being applied to the token.

Example request:

{
  "displayName": "My token"
}

Responses

The following responses may be returned.

CodeDescription
200Successful operation

Example response:

{
  "id": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "accessPolicyId": "c45485b6-8321-4cf2-bcec-12006df755ff",
  "name": "mytoken",
  "displayName": "My token",
  "expiresAt": "2022-06-09T04:43:16.296Z",
  "firstUsedAt": "2022-06-09T04:43:16.296Z",
  "createdAt": "2022-06-09T04:43:16.296Z",
  "updatedAt": "2022-06-09T04:43:16.296Z"
}
CodeDescription
400Bad request
401API token is missing or invalid

Delete a token

Remove a specified token with the DELETE method.

DELETE http://www.grafana.com/api/v1/tokens/{tokenId}

Parameters

NameDescription
regionRequired. String. Query. Region where the API is deployed. Generally where the stack is deployed. Available values are us, eu, and au.
tokenIdRequired. String (UUID). Path. ID of the Token.

Responses

The following responses may be returned.

CodeDescription
204Token deleted successfully
400Bad request
401API token is missing or invalid