创建设备 Create device
本文内容
命名空间:microsoft.graph Namespace: microsoft.graph
在组织中创建并注册一个新设备。 Create and register a new device in the organization.
权限 Permissions
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。 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)
Directory.AccessAsUser.All Directory.AccessAsUser.All
委派(个人 Microsoft 帐户) Delegated (personal Microsoft account)
不支持。 Not supported.
应用程序 Application
Device.ReadWrite.All Device.ReadWrite.All
HTTP 请求 HTTP request
POST /devices
名称 Name
类型 Type
说明 Description
Authorization Authorization
string string
Bearer {token}。必需。 Bearer {token}. Required.
Content-type Content-type
string string
application/json application/json
请求正文 Request body
在请求正文中,提供 device 对象的 JSON 表示形式。 In the request body, supply a JSON representation of device object.
响应 Response
如果成功,此方法在响应正文中返回 201 Created
响应代码 device 对象。 If successful, this method returns 201 Created
response code and device object in the response body.
示例 Example
请求 Request
下面是一个请求示例。 Here is an example of the request.
POST https://graph.microsoft.com/v1.0/devices
Content-type: application/json
{
"accountEnabled":false,
"alternativeSecurityIds":
[
{
"type":2,
"key":"base64Y3YxN2E1MWFlYw=="
}
],
"deviceId":"4c299165-6e8f-4b45-a5ba-c5d250a707ff",
"displayName":"Test device",
"operatingSystem":"linux",
"operatingSystemVersion":"1"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var device = new Device
{
AccountEnabled = false,
AlternativeSecurityIds = new List<AlternativeSecurityId>()
{
new AlternativeSecurityId
{
Type = 2,
Key = Encoding.ASCII.GetBytes("base64Y3YxN2E1MWFlYw==")
}
},
DeviceId = "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
DisplayName = "Test device",
OperatingSystem = "linux",
OperatingSystemVersion = "1"
};
await graphClient.Devices
.Request()
.AddAsync(device);
阅读 sdk 文档 ,了解有关如何 将 SDK 添加 到您的项目并 创建 authProvider 实例的详细信息。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
const device = {
accountEnabled:false,
alternativeSecurityIds:
[
{
type:2,
key:"base64Y3YxN2E1MWFlYw=="
}
],
deviceId:"4c299165-6e8f-4b45-a5ba-c5d250a707ff",
displayName:"Test device",
operatingSystem:"linux",
operatingSystemVersion:"1"
};
let res = await client.api('/devices')
.post(device);
阅读 sdk 文档 ,了解有关如何 将 SDK 添加 到您的项目并 创建 authProvider 实例的详细信息。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphDevice *device = [[MSGraphDevice alloc] init];
[device setAccountEnabled: false];
NSMutableArray *alternativeSecurityIdsList = [[NSMutableArray alloc] init];
MSGraphAlternativeSecurityId *alternativeSecurityIds = [[MSGraphAlternativeSecurityId alloc] init];
[alternativeSecurityIds setType: 2];
[alternativeSecurityIds setKey:@"base64Y3YxN2E1MWFlYw=="];
[alternativeSecurityIdsList addObject: alternativeSecurityIds];
[device setAlternativeSecurityIds:alternativeSecurityIdsList];
[device setDeviceId:@"4c299165-6e8f-4b45-a5ba-c5d250a707ff"];
[device setDisplayName:@"Test device"];
[device setOperatingSystem:@"linux"];
[device setOperatingSystemVersion:@"1"];
NSError *error;
NSData *deviceData = [device getSerializedDataWithError:&error];
[urlRequest setHTTPBody:deviceData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
阅读 sdk 文档 ,了解有关如何 将 SDK 添加 到您的项目并 创建 authProvider 实例的详细信息。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Device device = new Device();
device.accountEnabled = false;
LinkedList<AlternativeSecurityId> alternativeSecurityIdsList = new LinkedList<AlternativeSecurityId>();
AlternativeSecurityId alternativeSecurityIds = new AlternativeSecurityId();
alternativeSecurityIds.type = 2;
alternativeSecurityIds.key = Base64.getDecoder().decode("base64Y3YxN2E1MWFlYw==");
alternativeSecurityIdsList.add(alternativeSecurityIds);
device.alternativeSecurityIds = alternativeSecurityIdsList;
device.deviceId = "4c299165-6e8f-4b45-a5ba-c5d250a707ff";
device.displayName = "Test device";
device.operatingSystem = "linux";
device.operatingSystemVersion = "1";
graphClient.devices()
.buildRequest()
.post(device);
阅读 sdk 文档 ,了解有关如何 将 SDK 添加 到您的项目并 创建 authProvider 实例的详细信息。 Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
在请求正文中,提供 device 对象的 JSON 表示形式。 In the request body, supply a JSON representation of device object.
响应 Response
下面是一个响应示例。注意:为了简单起见,可能会将此处所示的响应对象截断。将从实际调用中返回所有属性。 Here is an example of the response. Note: The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.
HTTP/1.1 201 Created
Content-type: application/json
{
"accountEnabled":false,
"alternativeSecurityIds":
[
{
"type":2,
"key":"base64Y3YxN2E1MWFlYw=="
}
],
"deviceId":"4c299165-6e8f-4b45-a5ba-c5d250a707ff",
"displayName":"Test device",
"id": "id-value",
"operatingSystem":"linux",
"operatingSystemVersion":"1"
}