デバイスを取得する
[アーティクル]
06/29/2022
3 人の共同作成者
この記事の内容
名前空間: microsoft.graph
デバイス オブジェクトのプロパティとリレーションシップを取得します。
アクセス許可
この 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 プロパティではなく、デバイスの id プロパティの値です。
GET /devices/{id}
オプションのクエリ パラメーター
このメソッドは、応答を $selectカスタマイズするのに役立つ OData クエリ パラメーター をサポートします。
名前
型
説明
Authorization
string
ベアラー {token}。必須。
要求本文
このメソッドには、要求本文を指定しません。
応答
成功した場合、このメソッドは200 OK応答コードと、応答本文でデバイス オブジェクトを返します。
例
例 1: デバイスを取得する
要求
要求の例を次に示します。
GET https://graph.microsoft.com/v1.0/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDevice *device = [[MSGraphDevice alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Device device = graphClient.devices("000005c3-b7a6-4c61-89fc-80bf5ccfc366")
.buildRequest()
.get();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
deviceId := "device-id"
result, err := graphClient.DevicesById(&deviceId).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
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var device = await graphClient.Devices["{device-id}"]
.Request()
.Select("id,extensionAttributes")
.GetAsync();
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 のドキュメントを参照してください 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices/6a59ea83-02bd-468f-a40b-f2c3d1821983?$select=id,extensionAttributes"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDevice *device = [[MSGraphDevice alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Device device = graphClient.devices("6a59ea83-02bd-468f-a40b-f2c3d1821983")
.buildRequest()
.select("id,extensionAttributes")
.get();
SDK をプロジェクトに追加し、authProvider インスタンスを作成する 方法の詳細については、SDK のドキュメントを参照してください 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.DeviceRequestBuilderGetQueryParameters{
Select: "id,extensionAttributes",
}
options := &msgraphsdk.DeviceRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
deviceId := "device-id"
result, err := graphClient.DevicesById(&deviceId).GetWithRequestConfigurationAndResponseHandler(options, nil)
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
}
}