Skip to content

Commit 1737ec3

Browse files
committed
wip
1 parent 370e1ee commit 1737ec3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

articles/azure-monitor/essentials/rest-api-walkthrough.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ The Azure Monitor API also makes it possible to list alert rules, view activity
2020

2121
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.
2222

23+
## Create an service principal
2324

24-
# [Azure Portal](#tab/portal)
25+
### [Azure Portal](#tab/portal)
2526

2627
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)
2728

29+
### [Azure CLI](#tab/cli)
2830

29-
# [Azure CLI](#tab/cli)
3031

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.
3234

3335
```azurecli
34-
ad sp create-for-rbac -n <Service principal display name>
36+
az ad sp create-for-rbac -n <Service principal display name>
3537
3638
```
3739
The response looks as follows:
@@ -47,7 +49,19 @@ The response looks as follows:
4749
>[!Important]
4850
> 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.
4951
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+
5165

5266
To retrieve an access token using a REST call submit the following request using the `appId` and `password`:
5367

@@ -203,19 +217,13 @@ Loading the certificate from a .pfx file in PowerShell can make it easier for an
203217
---
204218

205219

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:
214222
- List the metric definitions for a resource.
215223
- Retrieve the metric values.
216224

217225
> [!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/).
219227
>
220228
221229
## Retrieve metric definitions

0 commit comments

Comments
 (0)