You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/essentials/rest-api-walkthrough.md
+22-14Lines changed: 22 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,18 +20,20 @@ The Azure Monitor API also makes it possible to list alert rules, view activity
20
20
21
21
Tasks executed using the Azure Monitor API use the Azure Resource Manager authentication model. All requests must be authenticated with Azure Active Directory (Azure AD). One approach to authenticating the client application is to create an Azure AD service principal and retrieve the authentication (JWT) token.
22
22
23
+
## Create an service principal
23
24
24
-
# [Azure Portal](#tab/portal)
25
+
###[Azure Portal](#tab/portal)
25
26
26
27
To create an Azure AD service principal using the Azure Portal see [Register an App to request authorization tokens and work with APIs](../logs/api/register-app-for-token)
27
28
29
+
### [Azure CLI](#tab/cli)
28
30
29
-
# [Azure CLI](#tab/cli)
30
31
31
-
Run the following script to create a service principal and app.
32
+
##
33
+
Run the following script to create a service principal and app.
32
34
33
35
```azurecli
34
-
ad sp create-for-rbac -n <Service principal display name>
36
+
az ad sp create-for-rbac -n <Service principal display name>
35
37
36
38
```
37
39
The response looks as follows:
@@ -47,7 +49,19 @@ The response looks as follows:
47
49
>[!Important]
48
50
> The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control.
49
51
50
-
For more information on creating a service principal using Azure CLI, see [AA](https://learn.microsoft.com/cli/azure/create-an-azure-service-principal-azure-cli)
52
+
Add a role and scope for the resouces that you want to access using the API
53
+
54
+
```azurecli
55
+
az role assignment create --assignee <`appId`> --role <Role> --scope <resource URI>
56
+
```
57
+
58
+
The example below assigns the `Reader` role to the service principal for all resources in the `rg-001`resource group:
59
+
```azurecli
60
+
az role assignment create --assignee 0a123b56-c987-1234-abcd-1a2b3c4d5e6f --role Reader --scope '\/subscriptions/a1234bcd-5849-4a5d-a2eb-5267eae1bbc7/resourceGroups/rg-001'
61
+
```
62
+
For more information on creating a service principal using Azure CLI, see [Create an Azure service principal with the Azure CLI](https://learn.microsoft.com/cli/azure/create-an-azure-service-principal-azure-cli)
63
+
64
+
51
65
52
66
To retrieve an access token using a REST call submit the following request using the `appId` and `password`:
53
67
@@ -203,19 +217,13 @@ Loading the certificate from a .pfx file in PowerShell can make it easier for an
203
217
---
204
218
205
219
206
-
## Roles
207
-
Assign role if necessary
208
-
209
-
210
-
211
-
212
-
After authenticating and retrieving a token, queries can then be executed against the Azure Monitor REST API. There are two helpful queries:
213
-
220
+
After authenticating and retrieving a token, queries can then be executed against the Azure Monitor REST API.
221
+
For metrics, the two most used queries are:
214
222
- List the metric definitions for a resource.
215
223
- Retrieve the metric values.
216
224
217
225
> [!NOTE]
218
-
> For more information on authenticating with the Azure REST API, see the [Azure REST API reference](/rest/api/azure/).
226
+
> For more information on working with the Azure REST API, see the [Azure REST API reference](/rest/api/azure/).
0 commit comments