LoginSignup
1
1

More than 1 year has passed since last update.

Microsoft Graph API は Azure CLI を使うと簡単便利だった

Last updated at Posted at 2022-04-03

背景と目的

Microsoft Graph は、Microsoft 365 関連リソースを操作出来る REST API です。GUI で Microsoft Graph API を操作するツールは色々ありますが、CUI 派の自分にとっては Azure CLI の 認証機能と REST リクエスト機能を使うと簡単便利だったので、使い方を紹介します。デフォルト設定で全ての Microsoft Graph API が使用出来るわけではありません。今回のサンプルは、自分が参加している Teams のチーム一覧を取得するという単純な例です。

Azure CLI で認証

https://docs.microsoft.com/ja-jp/cli/azure/authenticate-azure-cli

上記サイトを参考に Azure AD テナントにサインインします。

サインインするテナントに自分がアクセスできる Azure サブスクリプションがない場合は、以下のパラメーターを使ってみて下さい。

bash
az login --allow-no-subscriptions

Azure CLI で Microsoft Graph API を操作

サインインしたユーザーの権限で API を実行します。

自分のプロファイルを表示する例

https://docs.microsoft.com/ja-JP/graph/api/user-get?view=graph-rest-1.0&tabs=http#example-2-signed-in-user-request

bash
az rest \
  --method get \
  --url https://graph.microsoft.com/v1.0/me

自分が参加しているチームの一覧を表示する例

https://docs.microsoft.com/ja-jp/graph/api/user-list-joinedteams?view=graph-rest-1.0&tabs=http#request

bash
az rest \
  --method get \
  --url https://graph.microsoft.com/v1.0/me/joinedTeams

参考

https://docs.microsoft.com/ja-jp/graph/use-the-api

https://developer.microsoft.com/ja-jp/graph/graph-explorer

https://docs.microsoft.com/ja-jp/cli/azure/reference-index?view=azure-cli-latest#az-rest

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1