デバイスを作成する
-
[アーティクル]
-
-
名前空間: microsoft.graph
新しいデバイスを作成し、組織に登録します。
アクセス許可
この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可」を参照してください。
| アクセス許可の種類 |
アクセス許可 (特権の小さいものから大きいものへ) |
| 委任 (職場または学校のアカウント) |
Directory.AccessAsUser.All |
| 委任 (個人用 Microsoft アカウント) |
サポートされていません。 |
| アプリケーション |
サポートされていません。 |
HTTP 要求
POST /devices
| 名前 |
説明 |
| Authorization |
ベアラー {token}。必須。 |
| Content-type |
application/json |
要求本文
要求本文で、デバイス オブジェクトの JSON 表記を指定します。
応答
成功した場合、このメソッドは 201 Created 応答コードと、応答本文でデバイス オブジェクトを返します。
例
要求
以下は、要求の例です。
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 = Convert.FromBase64String("base64Y3YxN2E1MWFlYw==")
}
},
DeviceId = "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
DisplayName = "Test device",
OperatingSystem = "linux",
OperatingSystemVersion = "1"
};
await graphClient.Devices
.Request()
.AddAsync(device);
SDK をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
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'
};
await client.api('/devices')
.post(device);
SDK をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
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 をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
GraphServiceClient 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 をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewDevice()
accountEnabled := false
requestBody.SetAccountEnabled(&accountEnabled)
requestBody.SetAlternativeSecurityIds( []AlternativeSecurityId {
msgraphsdk.NewAlternativeSecurityId(),
SetAdditionalData(map[string]interface{}{
"type": ,
"key": "base64Y3YxN2E1MWFlYw==",
}
}
deviceId := "4c299165-6e8f-4b45-a5ba-c5d250a707ff"
requestBody.SetDeviceId(&deviceId)
displayName := "Test device"
requestBody.SetDisplayName(&displayName)
operatingSystem := "linux"
requestBody.SetOperatingSystem(&operatingSystem)
operatingSystemVersion := "1"
requestBody.SetOperatingSystemVersion(&operatingSystemVersion)
result, err := graphClient.Devices().Post(requestBody)
SDK をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
AccountEnabled = $false
AlternativeSecurityIds = @(
@{
Type = 2
Key = [System.Text.Encoding]::ASCII.GetBytes("base64Y3YxN2E1MWFlYw==")
}
)
DeviceId = "4c299165-6e8f-4b45-a5ba-c5d250a707ff"
DisplayName = "Test device"
OperatingSystem = "linux"
OperatingSystemVersion = "1"
}
New-MgDevice -BodyParameter $params
SDK をプロジェクトに追加し、authProvider インスタンスを作成する方法の詳細については、SDK のドキュメントを参照してください。
要求本文で、デバイス オブジェクトの JSON 表記を指定します。
応答
以下に応答の例を示します。注: ここに示す応答オブジェクトは、読みやすさのために短縮されている可能性があります。
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"
}