命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
返回 ID 列表中指定的目录对象。
该函数的一些常见用途是:
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Directory.Read.All |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Directory.Read.All |
不可用。 |
重要
当应用程序查询返回 directoryObject 类型集合的关系时,如果它没有读取特定资源类型的权限,则会返回该类型的成员,但信息有限。 例如,仅返回对象类型和 ID 的 @odata.type 属性,而其他属性则指示为 null
。 通过此行为,应用程序可以请求所需的最低特权权限,而不是依赖于 目录集。*权限。 有关详细信息,请参阅为不可访问的成员对象返回有限的信息。
HTTP 请求
POST /directoryObjects/getByIds
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-type |
application/json. 必需。 |
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
响应
如果成功,此方法在响应正文中返回 200 OK
响应代码和 String 集合对象。
示例
请求
POST https://graph.microsoft.com/beta/directoryObjects/getByIds
Content-type: application/json
{
"ids": [
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",
"0b944de3-e0fc-4774-a49a-b135213725ef",
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0"
],
"types": [
"user",
"group",
"device"
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.DirectoryObjects.GetByIds;
var requestBody = new GetByIdsPostRequestBody
{
Ids = new List<string>
{
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",
"0b944de3-e0fc-4774-a49a-b135213725ef",
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0",
},
Types = new List<string>
{
"user",
"group",
"device",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.DirectoryObjects.GetByIds.PostAsGetByIdsPostResponseAsync(requestBody);
mgc-beta directory-objects get-by-ids post --body '{\
"ids": [\
"84b80893-8749-40a3-97b7-68513b600544",\
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",\
"0b944de3-e0fc-4774-a49a-b135213725ef",\
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0"\
],\
"types": [\
"user",\
"group",\
"device"\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdirectoryobjects "github.com/microsoftgraph/msgraph-beta-sdk-go/directoryobjects"
//other-imports
)
requestBody := graphdirectoryobjects.NewGetByIdsPostRequestBody()
ids := []string {
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",
"0b944de3-e0fc-4774-a49a-b135213725ef",
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0",
}
requestBody.SetIds(ids)
types := []string {
"user",
"group",
"device",
}
requestBody.SetTypes(types)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
getByIds, err := graphClient.DirectoryObjects().GetByIds().PostAsGetByIdsPostResponse(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.directoryobjects.getbyids.GetByIdsPostRequestBody getByIdsPostRequestBody = new com.microsoft.graph.beta.directoryobjects.getbyids.GetByIdsPostRequestBody();
LinkedList<String> ids = new LinkedList<String>();
ids.add("84b80893-8749-40a3-97b7-68513b600544");
ids.add("5d6059b6-368d-45f8-91e1-8e07d485f1d0");
ids.add("0b944de3-e0fc-4774-a49a-b135213725ef");
ids.add("b75a5ab2-fe55-4463-bd31-d21ad555c6e0");
getByIdsPostRequestBody.setIds(ids);
LinkedList<String> types = new LinkedList<String>();
types.add("user");
types.add("group");
types.add("device");
getByIdsPostRequestBody.setTypes(types);
var result = graphClient.directoryObjects().getByIds().post(getByIdsPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
ids: [
'84b80893-8749-40a3-97b7-68513b600544',
'5d6059b6-368d-45f8-91e1-8e07d485f1d0',
'0b944de3-e0fc-4774-a49a-b135213725ef',
'b75a5ab2-fe55-4463-bd31-d21ad555c6e0'
],
types: [
'user',
'group',
'device'
]
};
await client.api('/directoryObjects/getByIds')
.version('beta')
.post(directoryObject);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\DirectoryObjects\GetByIds\GetByIdsPostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GetByIdsPostRequestBody();
$requestBody->setIds(['84b80893-8749-40a3-97b7-68513b600544', '5d6059b6-368d-45f8-91e1-8e07d485f1d0', '0b944de3-e0fc-4774-a49a-b135213725ef', 'b75a5ab2-fe55-4463-bd31-d21ad555c6e0', ]);
$requestBody->setTypes(['user', 'group', 'device', ]);
$result = $graphServiceClient->directoryObjects()->getByIds()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.DirectoryObjects
$params = @{
ids = @(
"84b80893-8749-40a3-97b7-68513b600544"
"5d6059b6-368d-45f8-91e1-8e07d485f1d0"
"0b944de3-e0fc-4774-a49a-b135213725ef"
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0"
)
types = @(
"user"
"group"
"device"
)
}
Get-MgBetaDirectoryObjectById -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.directoryobjects.get_by_ids.get_by_ids_post_request_body import GetByIdsPostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = GetByIdsPostRequestBody(
ids = [
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",
"0b944de3-e0fc-4774-a49a-b135213725ef",
"b75a5ab2-fe55-4463-bd31-d21ad555c6e0",
],
types = [
"user",
"group",
"device",
],
)
result = await graph_client.directory_objects.get_by_ids.post(request_body)
响应
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directoryObjects",
"value": [
{
"@odata.type": "#microsoft.graph.user",
"id": "84b80893-8749-40a3-97b7-68513b600544",
"accountEnabled": true,
"displayName": "Trevor Jones"
},
{
"@odata.type": "#microsoft.graph.user",
"id": "5d6059b6-368d-45f8-91e1-8e07d485f1d0",
"accountEnabled": true,
"displayName": "Billy Smith"
},
{
"@odata.type": "#microsoft.graph.group",
"id": "0b944de3-e0fc-4774-a49a-b135213725ef",
"description": "Pineview School Staff",
"groupTypes": [
"Unified"
]
},
{
"@odata.type": "#microsoft.graph.device",
"id": "b75a5ab2-fe55-4463-bd31-d21ad555c6e0",
"displayName": "e8ba4e98c000002",
"deviceId": "4c299165-6e8f-4b45-a5ba-c5d250a707ff"
}
]
}