Graph API の一般的なクエリ
このトピックでは、Azure AD Graph API で実行できる一般的なクエリの一部を一覧します。 Graph をクエリする際にサポートされている操作の詳細については、「Azure AD Graph API でサポートされているクエリ、フィルター、およびページング オプション」を参照してください。
重要
Azure Active Directory のリソースにアクセスするには、Azure AD Graph API ではなく Microsoft Graph を使用することを強くお勧めします。現在は Microsoft Graph を中心にして開発が進められており、Azure AD Graph API の今後の機能強化は予定されていません。Azure AD Graph API の使用が適切である場合もありますが、非常にまれです。詳細については、Office Dev Center の Microsoft Graph または Azure AD Graph ブログの記事をご覧ください。
アドレス指定
次のクエリはいずれも、ドメイン名を使用してテナントのアドレスを指定しています。 contoso.com は、テナントの登録済みのドメイン名のいずれか、テナントの ID (GUID)、または MyOrganization
エイリアス (委任アクセスの場合) に置換できます。 テナントのアドレスを指定するその他の方法については、「Graph API のエンティティと操作のアドレス指定」を参照してください。
トップ レベル リソースに対するクエリ
次の一般的なクエリでは、contoso.com をサンプル テナントとして使用して Graph API でトップ レベル リソースにアクセスする方法を示します。 テナントに対してクエリを実行するには、Azure AD から受信した有効なベアラー トークンを含む Authorization ヘッダーが必要になります。
トップ レベル リソース | クエリ結果 | URI (contoso.com の場合) |
---|---|---|
トップ レベル リソース | ディレクトリ サービスに対応するトップ レベル リソースの URI リストを返します (同じものを下にも記載してあります) | https://graph.windows.net/contoso.com?api-version=1.6 |
会社情報 | 会社情報を返します | https://graph.windows.net/contoso.com/tenantDetails?api-version=1.6 |
連絡先 | 組織の連絡先情報を返します | https://graph.windows.net/contoso.com/contacts?api-version=1.6 |
Users | ユーザー情報を返します | https://graph.windows.net/contoso.com/users?api-version=1.6 |
[グループ] | グループ データを返します | https://graph.windows.net/contoso.com/groups?api-version=1.6 |
ディレクトリ ロール | テナント内のアクティブ化されたディレクトリ ロールをすべて返します | https://graph.windows.net/contoso.com/roles?api-version=1.6 |
SubscribedSkus | テナントのサブスクリプションを返します | https://graph.windows.net/contoso.com/subscribedSkus?api-version=1.6 |
ディレクトリのメタデータ | データ モデルを記述したサービス メタデータ ドキュメント (つまり、ディレクトリ リソースの構造と編成) を返します | https://graph.windows.net/contoso.com/$metadata?api-version=1.6 |
クエリ操作
次の表では、contoso.com をテナントとして使用した Graph API クエリの例をいくつか紹介します。
クエリ操作: | URI (contoso.com の場合) |
---|---|
ユーザーとグループをすべてリストします | https://graph.windows.net/contoso.com/users?api-version=1.6 https://graph.windows.net/contoso.com/groups?api-version=1.6 |
objectId または userPrincipalName を指定して、個々のユーザーを取得します | https://graph.windows.net/contoso.com/users/d1f67a6c-02c9-4fe5-81fb-58160ce24fe5?api-version=1.6 https://graph.windows.net/contoso.com/users/admin@contoso.com?api-version=1.6 |
displayName が "Jon Doe" に等しいユーザーを要求してフィルター処理します | https://graph.windows.net/contoso.com/Users?$filter=displayName eq 'Jon Doe'&api-version=1.6 |
firstName が "Jon" に等しい特定のユーザーを要求してフィルター処理します | https://graph.windows.net/contoso.com/users?$filter=givenName eq 'Jon'&api-version=1.6 |
givenName と surname の値を対象にしてフィルター処理します。 | https://graph.windows.net/contoso.com/users?$filter=givenName eq 'Jon' and surname eq 'Doe'&api-version=1.6 |
objectId を指定して、個々のグループを取得します | https://graph.windows.net/contoso.com/groups/06790a81-0382-434c-b40e-216fa41bda21?api-version=1.6 |
ユーザーを指定し、そのユーザーの管理者を取得します | https://graph.windows.net/contoso.com/users/John.Smith@contoso.com/manager?api-version=1.6 |
ユーザーの直属の部下一覧を取得します。 | https://graph.windows.net/contoso.com/users/3c4a09b0-a7b6-444e-9702-96983635a66e/directReports?api-version=1.6 |
ユーザーの直属の部下に対応するリンクの一覧を取得します | https://graph.windows.net/contoso.com/users/3c4a09b0-a7b6-444e-9702-96983635a66e/$links/directReports?api-version=1.6 |
グループのメンバーシップの一覧を取得します | https://graph.windows.net/contoso.com/groups/3f575eef-bb04-44a5-a9af-eee9f547e3f9/members?api-version=1.6 |
グループのメンバーに対応するリンクの一覧を取得します。 | https://graph.windows.net/contoso.com/groups/3f575eef-bb04-44a5-a9af-eee9f547e3f9/$links/members?api-version=1.6 |
ユーザーのグループ メンバーシップを取得します (推移なし) | https://graph.windows.net/contoso.com/users/ee6308f6-646a-4845-a4e1-57ac96ccc0c8/memberOf?api-version=1.6 |
ユーザーがメンバーになっているグループの一覧を取得します (推移なし) | https://graph.windows.net/contoso.com/users/ee6308f6-646a-4845-a4e1-57ac96ccc0c8/$links/memberOf?api-version=1.6 |
displayName >= "az" かつ <= "dz" というグループを要求してフィルター処理します | https://graph.windows.net/contoso.com/groups?$filter=displayName ge 'az' and displayName le 'dz'&api-version=1.6 |
注: クエリ文字列内の空白は、要求を送信する前に URL エンコードする必要があります。 たとえば、https://graph.windows.net/contoso.com/Users?$filter=displayName eq 'Jon Doe'&api-version=1.6
というクエリ文字列は、https://graph.windows.net/contoso.com/Users?$filter=displayName%20eq%20'Jon%20Doe'&api-version=1.6
という URL にエンコードされます。