デバイスを取得する
[アーティクル]
10/30/2023
15 人の共同作成者
フィードバック
この記事の内容
名前空間: microsoft.graph
デバイス オブジェクトのプロパティとリレーションシップを取得します。
この API は、次の国内クラウド展開 で使用できます。
グローバル サービス
米国政府機関 L4
米国政府機関 L5 (DOD)
21Vianet が運営する中国
✅
✅
✅
✅
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。 アプリで必要な場合にのみ 、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「 アクセス許可の種類 」を参照してください。 これらのアクセス許可の詳細については、 アクセス許可のリファレンスを参照してください 。
アクセス許可の種類
最小特権アクセス許可
特権の高いアクセス許可
委任 (職場または学校のアカウント)
Device.Read.All
Directory.Read.All、Directory.ReadWrite.All
委任 (個人用 Microsoft アカウント)
サポートされていません。
サポートされていません。
アプリケーション
Device.Read.All
Device.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All
HTTP 要求
ID または deviceId を使用してデバイスをアドレス指定できます。
GET /devices/{id}
GET /devices(deviceId='{deviceId}')
オプションのクエリ パラメーター
このメソッドは、応答のカスタマイズに$select
役立つ OData クエリ パラメーター をサポートします。
名前
型
説明
Authorization
string
ベアラー {token}。 必須です。
要求本文
このメソッドには、要求本文を指定しません。
応答
成功した場合、このメソッドは200 OK
応答コードと、応答本文でデバイス オブジェクトを返します。
例
例 1: デバイスを取得する
要求
次の例は要求を示しています。
GET https://graph.microsoft.com/v1.0/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices["{device-id}"].GetAsync();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
devices, err := graphClient.Devices().ByDeviceId("device-id").Get(context.Background(), nil)
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Device result = graphClient.devices().byDeviceId("{device-id}").get();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
const options = {
authProvider,
};
const client = Client.init(options);
let device = await client.api('/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366')
.get();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
<?php
use Microsoft\Graph\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->devices()->byDeviceId('device-id')->get()->wait();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
from msgraph import GraphServiceClient
graph_client = GraphServiceClient(credentials, scopes)
result = await graph_client.devices.by_device_id('device-id').get()
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
応答
次の例は応答を示しています。
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#devices/$entity",
"@odata.id": "https://graph.microsoft.com/v2/72f988bf-86f1-41af-91ab-2d7cd011db47/directoryObjects/000005c3-b7a6-4c61-89fc-80bf5ccfc366/Microsoft.DirectoryServices.Device",
"accountEnabled":false,
"deviceId":"6fa60d52-01e7-4b18-8055-4759461fc16b",
"displayName":"DESKTOP-858MANH",
"id": "000005c3-b7a6-4c61-89fc-80bf5ccfc366",
"operatingSystem":"Windows",
"operatingSystemVersion":"10.0.19043.1165"
}
例 2: デバイスを取得し、その ID と extensionAttributes プロパティのみを返す
要求
次の要求は、デバイスの ID と extensionAttributes プロパティを取得します。
GET https://graph.microsoft.com/beta/devices/6a59ea83-02bd-468f-a40b-f2c3d1821983?$select=id,extensionAttributes
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices["{device-id}"].GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string []{ "id","extensionAttributes" };
});
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta devices get --device-id {device-id} --select "id,extensionAttributes"
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdevices "github.com/microsoftgraph/msgraph-beta-sdk-go/devices"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestParameters := &graphdevices.DeviceItemRequestBuilderGetQueryParameters{
Select: [] string {"id","extensionAttributes"},
}
configuration := &graphdevices.DeviceItemRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
devices, err := graphClient.Devices().ByDeviceId("device-id").Get(context.Background(), configuration)
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Device result = graphClient.devices().byDeviceId("{device-id}").get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String []{"id", "extensionAttributes"};
});
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
const options = {
authProvider,
};
const client = Client.init(options);
let device = await client.api('/devices/6a59ea83-02bd-468f-a40b-f2c3d1821983')
.version('beta')
.select('id,extensionAttributes')
.get();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Devices\Item\DeviceItemRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new DeviceItemRequestBuilderGetRequestConfiguration();
$queryParameters = DeviceItemRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->select = ["id","extensionAttributes"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->devices()->byDeviceId('device-id')->get($requestConfiguration)->wait();
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
Get-MgBetaDevice -DeviceId $deviceId -Property "id,extensionAttributes"
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
from msgraph import GraphServiceClient
from msgraph.generated.devices.item.device_item_request_builder import DeviceItemRequestBuilder
graph_client = GraphServiceClient(credentials, scopes)
query_params = DeviceItemRequestBuilder.DeviceItemRequestBuilderGetQueryParameters(
select = ["id","extensionAttributes"],
)
request_configuration = DeviceItemRequestBuilder.DeviceItemRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.devices.by_device_id('device-id').get(request_configuration = request_configuration)
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
応答
次の例は応答を示しています。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#devices(id,extensionAttributes)/$entity",
"id": "6a59ea83-02bd-468f-a40b-f2c3d1821983",
"extensionAttributes": {
"extensionAttribute1": "BYOD-Device",
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
"extensionAttribute5": null,
"extensionAttribute6": null,
"extensionAttribute7": null,
"extensionAttribute8": null,
"extensionAttribute9": null,
"extensionAttribute10": null,
"extensionAttribute11": null,
"extensionAttribute12": null,
"extensionAttribute13": null,
"extensionAttribute14": null,
"extensionAttribute15": null
}
}