Skip to content

Commit b26352d

Browse files
Merge pull request #233394 from zioproto/zioproto-patch-1
Document the "az grafana api-key create" command
2 parents 62ba229 + d999352 commit b26352d

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

articles/managed-grafana/how-to-api-calls.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: maud-lv
66
ms.author: malev
77
ms.service: managed-grafana
88
ms.topic: tutorial
9-
ms.date: 03/23/2023
9+
ms.date: 04/05/2023
1010
ms.custom: engagement-fy23
1111
---
1212

@@ -83,7 +83,34 @@ You now need to gather some information, which you'll use to get a Grafana API a
8383

8484
## Get an access token
8585

86-
To access Grafana APIs, you need to get an access token. Follow the example below to call Azure AD and retrieve a token. Replace `<tenant-id>`, `<client-id>`, and `<client-secret>` with the tenant ID, application (client) ID, and client secret collected in the previous step.
86+
To access Grafana APIs, you need to get an access token. You can get the access token using the Azure CLI or making a POST request.
87+
88+
### [Azure CLI](#tab/azure-cli)
89+
90+
Sign in to the Azure CLI by running the [az login](/cli/azure/reference-index#az-login) command and replace `<client-id>`, `<client-secret>`, and `<tenant-id>` with the application (client) ID, client secret, and tenant ID collected in the previous step:
91+
92+
```
93+
az login --service-principal --username "<client-id>" --password "<client-secret>" --tenant "<tenant-id>"
94+
```
95+
96+
Use the command [az grafana api-key create](/cli/azure/grafana/api-key#az-grafana-api-key-create) to create a key. Here's an example output:
97+
98+
```
99+
az grafana api-key create --key keyname --name <name> --resource-group <rg> --resource-group editor --output json
100+
101+
{
102+
"id": 3,
103+
"key": "<redacted>",
104+
"name": "keyname"
105+
}
106+
```
107+
108+
> [!NOTE]
109+
> You can only view this key here once. Save it in a secure place.
110+
111+
### [POST request](#tab/post)
112+
113+
Follow the example below to call Azure AD and retrieve a token. Replace `<tenant-id>`, `<client-id>`, and `<client-secret>` with the tenant ID, application (client) ID, and client secret collected in the previous step.
87114

88115
```bash
89116
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
@@ -105,6 +132,8 @@ Here's an example of response:
105132
}
106133
```
107134

135+
---
136+
108137
## Call Grafana APIs
109138

110139
You can now call Grafana APIs using the access token retrieved in the previous step as the Authorization header. For example:

0 commit comments

Comments
 (0)