毎回忘れちゃうので自分用メモとして残します。
Cloud Shell(Bash)
-
Azure PortalにログインしてCloud Shell(Bash)を開きます。
-
アクセストークンを取得します。
token=`az account get-access-token | jq -r .accessToken`
- 対象のREST APIを実行します(ここでは例としてリソースグループ一覧を取得しています)
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://management.azure.com/subscriptions/[Subsciption Id]/resourcegroups?api-version=2021-04-01 | jq .
Azure CLI(ローカル実行)
-
ここではWindowsPCでの実行を想定しています。まずはPowerShellを開きます。
-
Azureにログインします。
az login
- アクセストークンを取得します。
$token = az account get-access-token | ConvertFrom-Json
$token = $token.accessToken
- 対象のREST APIを実行します(ここでは例としてリソースグループ一覧を取得しています)
$res = Invoke-WebRequest -Method GET -Headers @{"Content-Type"="application/json"; "Authorization"="Bearer $token"} https://management.azure.com/subscriptions/[Subsciption Id]/resourcegroups?api-version=2021-04-01
ConvertFrom-Json $res.Content | ConvertTo-Json
以上です