Azureのサポートチケット関連操作をAPIで実行する必要があり、いくつかAPIを試したので書き残します。
アクセストークン取得
-
Azure PortalにログインしてCloudShell(Bash)を開きます
-
アクセストークンを取得します
token=`az account get-access-token | jq -r .accessToken`
各種API操作
サポートチケット一覧取得
- 以下コマンドでサポートチケット一覧を取得できます
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://management.azure.com/subscriptions/[Subscription ID]/providers/Microsoft.Support/supportTickets?api-version=2020-04-01 | jq .
- 最も最近クローズになったサポートチケットのTicket Nameを取得します
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://management.azure.com/subscriptions/[Subscription ID]/providers/Microsoft.Support/supportTickets?api-version=2020-04-01 | jq -r '.value | map(select(.properties.status == "Closed")) | sort_by(.properties.modifiedDate) | reverse | .[0].name'
サポートチケットの詳細取得
- 取得したTicket Nameを指定して、チケットの詳細を取得します
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://management.azure.com/subscriptions/[Subscription ID]/providers/Microsoft.Support/supportTickets/[Ticket Name]/communications?api-version=2020-04-01 | jq .
- やり取りが長い場合はnextLinkが出力されるので続きを取得できます
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" https://management.azure.com/subscriptions/[Subscription ID]/providers/Microsoft.Support/supportTickets/[Ticket Name]/communications?api-version=2020-04-01 | jq -r .nextLink
curl -X GET -L -H "Content-Type: application/json" -H "Authorization: Bearer $token" '[nextLink]' | jq .
以上です