Get device
Artikel
07/27/2022
3 menit untuk membaca
12 kontributor
Dalam artikel ini
Namespace: microsoft.graph
Get the properties and relationships of a device object.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Device.Read.All, Directory.Read.All, Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Device.Read.All, Device.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All
HTTP request
The {id} in the request is the value of the id property of the device, not the deviceId property.
GET /devices/{id}
Optional query parameters
This method supports the $select OData query parameter to help customize the response.
Name
Type
Description
Authorization
string
Bearer {token}. Required.
Request body
Do not supply a request body for this method.
Response
If successful, this method returns a 200 OK response code and device object in the response body.
Examples
Example 1: Get a device
Request
The following is an example of the request.
GET https://graph.microsoft.com/v1.0/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var device = await graphClient.Devices["{device-id}"]
.Request()
.GetAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
let device = await client.api('/devices/000005c3-b7a6-4c61-89fc-80bf5ccfc366')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Device device = graphClient.devices("000005c3-b7a6-4c61-89fc-80bf5ccfc366")
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.DevicesById("device-id").Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestResult = $graphServiceClient->devicesById('device-id')->get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
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"
}
Example 2: Get a device and return only its id and extensionAttributes properties
Request
The following request retrieves the id and extensionAttributes property of a device.
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();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
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();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Device device = graphClient.devices("6a59ea83-02bd-468f-a40b-f2c3d1821983")
.buildRequest()
.select("id,extensionAttributes")
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &graphconfig.DeviceRequestBuilderGetQueryParameters{
Select: [] string {"id","extensionAttributes"},
}
configuration := &graphconfig.DeviceRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
result, err := graphClient.DevicesById("device-id").GetWithRequestConfigurationAndResponseHandler(configuration, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new DeviceRequestBuilderGetRequestConfiguration();
$queryParameters = new DeviceRequestBuilderGetQueryParameters();
$queryParameters->select = ["id","extensionAttributes"];
$requestConfiguration->queryParameters = $queryParameters;
$requestResult = $graphServiceClient->devicesById('device-id')->get($requestConfiguration);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
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
}
}