デバイスを作成する
[アーティクル]
03/15/2024
12 人の共同作成者
フィードバック
この記事の内容
名前空間: microsoft.graph
新しいデバイスを作成し、組織に登録します。
この API は、次の国内クラウド展開 で使用できます。
グローバル サービス
米国政府機関 L4
米国政府機関 L5 (DOD)
21Vianet が運営する中国
✅
✅
✅
✅
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。 アプリで必要な場合にのみ 、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「 アクセス許可の種類 」を参照してください。 これらのアクセス許可の詳細については、 アクセス許可のリファレンスを参照してください 。
アクセス許可の種類
最小特権アクセス許可
特権の高いアクセス許可
委任 (職場または学校のアカウント)
Directory.AccessAsUser.All
注意事項なし。
委任 (個人用 Microsoft アカウント)
サポートされていません。
サポートされていません。
アプリケーション
サポートされていません。
サポートされていません。
呼び出し元のユーザーは、Intune Administrator、または Windows 365 Administrator のいずれかのMicrosoft Entraロール に含まれている必要もあります 。
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"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = 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",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices.PostAsync(requestBody);
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc devices create --body '{\
"accountEnabled":false,\
"alternativeSecurityIds":\
[\
{\
"type":2,\
"key":"base64Y3YxN2E1MWFlYw=="\
}\
],\
"deviceId":"4c299165-6e8f-4b45-a5ba-c5d250a707ff",\
"displayName":"Test device",\
"operatingSystem":"linux",\
"operatingSystemVersion":"1"\
}\
'
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewDevice()
accountEnabled := false
requestBody.SetAccountEnabled(&accountEnabled)
alternativeSecurityId := graphmodels.NewAlternativeSecurityId()
type := int32(2)
alternativeSecurityId.SetType(&type)
key := []byte("base64Y3YxN2E1MWFlYw==")
alternativeSecurityId.SetKey(&key)
alternativeSecurityIds := []graphmodels.AlternativeSecurityIdable {
alternativeSecurityId,
}
requestBody.SetAlternativeSecurityIds(alternativeSecurityIds)
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)
devices, err := graphClient.Devices().Post(context.Background(), requestBody, nil)
プロジェクトに SDK を追加 し、authProvider インスタンスを作成 する方法の詳細については、SDK のドキュメント を参照してください。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Device device = new Device();
device.setAccountEnabled(false);
LinkedList<AlternativeSecurityId> alternativeSecurityIds = new LinkedList<AlternativeSecurityId>();
AlternativeSecurityId alternativeSecurityId = new AlternativeSecurityId();
alternativeSecurityId.setType(2);
byte[] key = Base64.getDecoder().decode("base64Y3YxN2E1MWFlYw==");
alternativeSecurityId.setKey(key);
alternativeSecurityIds.add(alternativeSecurityId);
device.setAlternativeSecurityIds(alternativeSecurityIds);
device.setDeviceId("4c299165-6e8f-4b45-a5ba-c5d250a707ff");
device.setDisplayName("Test device");
device.setOperatingSystem("linux");
device.setOperatingSystemVersion("1");
Device result = graphClient.devices().post(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 のドキュメント を参照してください。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\Device;
use Microsoft\Graph\Generated\Models\AlternativeSecurityId;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Device();
$requestBody->setAccountEnabled(false);
$alternativeSecurityIdsAlternativeSecurityId1 = new AlternativeSecurityId();
$alternativeSecurityIdsAlternativeSecurityId1->setType(2);
$alternativeSecurityIdsAlternativeSecurityId1->setKey(\GuzzleHttp\Psr7\Utils::streamFor(base64_decode('base64Y3YxN2E1MWFlYw==')));
$alternativeSecurityIdsArray []= $alternativeSecurityIdsAlternativeSecurityId1;
$requestBody->setAlternativeSecurityIds($alternativeSecurityIdsArray);
$requestBody->setDeviceId('4c299165-6e8f-4b45-a5ba-c5d250a707ff');
$requestBody->setDisplayName('Test device');
$requestBody->setOperatingSystem('linux');
$requestBody->setOperatingSystemVersion('1');
$result = $graphServiceClient->devices()->post($requestBody)->wait();
プロジェクトに 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 のドキュメント を参照してください。
from msgraph import GraphServiceClient
from msgraph.generated.models.device import Device
from msgraph.generated.models.alternative_security_id import AlternativeSecurityId
graph_client = GraphServiceClient(credentials, scopes)
request_body = Device(
account_enabled = False,
alternative_security_ids = [
AlternativeSecurityId(
type = 2,
key = base64.urlsafe_b64decode("base64Y3YxN2E1MWFlYw=="),
),
],
device_id = "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
display_name = "Test device",
operating_system = "linux",
operating_system_version = "1",
)
result = await graph_client.devices.post(request_body)
プロジェクトに 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"
}