命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建一个新的 deviceTemplate ,用于标识属性和管理具有类似特征的一组设备。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
❌ |
❌ |
❌ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
DeviceTemplate.Create |
DeviceTemplate.ReadWrite.All |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
DeviceTemplate.Create |
DeviceTemplate.ReadWrite.All |
重要
在具有工作或学校帐户的委托方案中,必须为登录用户分配受支持的Microsoft Entra角色或具有支持的角色权限的自定义角色。 此作支持以下最低特权角色:
- 云设备管理员
- IoT 设备管理员
- 用户 - 设备模板对象的所有者
HTTP 请求
POST /directory/templates/deviceTemplates
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供 deviceTemplate 对象的 JSON 表示形式。
创建 deviceTemplate 时,可以指定以下属性。
属性 |
类型 |
说明 |
deviceAuthority |
String |
负责在Microsoft Entra租户上预配和管理设备的参与方的租户定义名称。 例如,Tailwind Traders (制造商) 制造安装在客户大楼中的安全摄像头,并由 Lakehore Retail (设备授权机构) 进行管理。 此值由设备颁发机构 (制造商或经销商) 提供给客户。 必填。 |
manufacturer |
String |
制造商名称。 必填。 |
model |
String |
模型名称。 必填。 |
mutualTlsOauthConfigurationId |
String |
mutualTlsOauthConfiguration 的对象 ID。 如果使用自签名证书而不是受信任的根证书,则不需要此值。 可选。 |
mutualTlsOauthConfigurationTenantId |
String |
ID (包含 mutualTlsOauthConfiguration 的租户的设备颁发机构) 的租户 ID。 如果使用自签名证书而不是受信任的根证书,则不需要此值。 可选。 |
operatingSystem |
String |
作系统类型。 可选。 |
owners@odata.bind |
字符串集合 |
所有者要添加到设备模板的 ID 列表。 仅支持以下 目录对象 类型作为所有者: 服务主体、 用户或 应用程序。 可选。 |
响应
如果成功,此方法在 201 Created
响应正文中返回响应代码和 deviceTemplate 对象。 如果在证书验证步骤期间发生验证失败,该方法将返回 并 400 Bad Request
返回消息“无法验证设备证书”。
有关详细信息,请参阅 Microsoft Graph 错误响应和资源类型。
示例
示例 1:创建新的设备模板
以下示例演示如何创建新的 deviceTemplate。
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/beta/directory/templates/deviceTemplates
Content-Type: application/json
Content-length: 106
{
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",
"deviceAuthority": "Lakeshore Retail",
"manufacturer": "Tailwind Traders",
"model": "DeepFreezerModelAB",
"operatingSystem": "WindowsIoT"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new DeviceTemplate
{
MutualTlsOauthConfigurationId = "00001111-aaaa-2222-bbbb-3333cccc4444",
MutualTlsOauthConfigurationTenantId = "00001111-aaaa-2222-bbbb-3333cccc4445",
DeviceAuthority = "Lakeshore Retail",
Manufacturer = "Tailwind Traders",
Model = "DeepFreezerModelAB",
OperatingSystem = "WindowsIoT",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Directory.Templates.DeviceTemplates.PostAsync(requestBody);
mgc-beta directory templates device-templates create --body '{\
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",\
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",\
"deviceAuthority": "Lakeshore Retail",\
"manufacturer": "Tailwind Traders",\
"model": "DeepFreezerModelAB",\
"operatingSystem": "WindowsIoT"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDeviceTemplate()
mutualTlsOauthConfigurationId := "00001111-aaaa-2222-bbbb-3333cccc4444"
requestBody.SetMutualTlsOauthConfigurationId(&mutualTlsOauthConfigurationId)
mutualTlsOauthConfigurationTenantId := "00001111-aaaa-2222-bbbb-3333cccc4445"
requestBody.SetMutualTlsOauthConfigurationTenantId(&mutualTlsOauthConfigurationTenantId)
deviceAuthority := "Lakeshore Retail"
requestBody.SetDeviceAuthority(&deviceAuthority)
manufacturer := "Tailwind Traders"
requestBody.SetManufacturer(&manufacturer)
model := "DeepFreezerModelAB"
requestBody.SetModel(&model)
operatingSystem := "WindowsIoT"
requestBody.SetOperatingSystem(&operatingSystem)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
deviceTemplates, err := graphClient.Directory().Templates().DeviceTemplates().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DeviceTemplate deviceTemplate = new DeviceTemplate();
deviceTemplate.setMutualTlsOauthConfigurationId("00001111-aaaa-2222-bbbb-3333cccc4444");
deviceTemplate.setMutualTlsOauthConfigurationTenantId("00001111-aaaa-2222-bbbb-3333cccc4445");
deviceTemplate.setDeviceAuthority("Lakeshore Retail");
deviceTemplate.setManufacturer("Tailwind Traders");
deviceTemplate.setModel("DeepFreezerModelAB");
deviceTemplate.setOperatingSystem("WindowsIoT");
DeviceTemplate result = graphClient.directory().templates().deviceTemplates().post(deviceTemplate);
const options = {
authProvider,
};
const client = Client.init(options);
const deviceTemplate = {
mutualTlsOauthConfigurationId: '00001111-aaaa-2222-bbbb-3333cccc4444',
mutualTlsOauthConfigurationTenantId: '00001111-aaaa-2222-bbbb-3333cccc4445',
deviceAuthority: 'Lakeshore Retail',
manufacturer: 'Tailwind Traders',
model: 'DeepFreezerModelAB',
operatingSystem: 'WindowsIoT'
};
await client.api('/directory/templates/deviceTemplates')
.version('beta')
.post(deviceTemplate);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\DeviceTemplate;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new DeviceTemplate();
$requestBody->setMutualTlsOauthConfigurationId('00001111-aaaa-2222-bbbb-3333cccc4444');
$requestBody->setMutualTlsOauthConfigurationTenantId('00001111-aaaa-2222-bbbb-3333cccc4445');
$requestBody->setDeviceAuthority('Lakeshore Retail');
$requestBody->setManufacturer('Tailwind Traders');
$requestBody->setModel('DeepFreezerModelAB');
$requestBody->setOperatingSystem('WindowsIoT');
$result = $graphServiceClient->directory()->templates()->deviceTemplates()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
mutualTlsOauthConfigurationId = "00001111-aaaa-2222-bbbb-3333cccc4444"
mutualTlsOauthConfigurationTenantId = "00001111-aaaa-2222-bbbb-3333cccc4445"
deviceAuthority = "Lakeshore Retail"
manufacturer = "Tailwind Traders"
model = "DeepFreezerModelAB"
operatingSystem = "WindowsIoT"
}
New-MgBetaDirectoryTemplateDeviceTemplate -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.device_template import DeviceTemplate
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = DeviceTemplate(
mutual_tls_oauth_configuration_id = "00001111-aaaa-2222-bbbb-3333cccc4444",
mutual_tls_oauth_configuration_tenant_id = "00001111-aaaa-2222-bbbb-3333cccc4445",
device_authority = "Lakeshore Retail",
manufacturer = "Tailwind Traders",
model = "DeepFreezerModelAB",
operating_system = "WindowsIoT",
)
result = await graph_client.directory.templates.device_templates.post(request_body)
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/templates/deviceTemplates/$entity",
"id": "c0ff9329-3596-4ece-8aa9-3dd23a925356",
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",
"deletedDateTime": null,
"deviceAuthority": "Lakeshore Retail",
"manufacturer": "Tailwind Traders",
"model": "DeepFreezerModelAB",
"operatingSystem": "WindowsIoT"
}
示例 2:创建具有所有者的设备模板
以下示例演示如何使用所有者创建新的 deviceTemplate 。
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/beta/directory/templates/deviceTemplates
Content-Type: application/json
Content-length: 106
{
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",
"deviceAuthority": "Lakeshore Retail",
"manufacturer": "Tailwind Traders",
"model": "DeepFreezerModelAB",
"operatingSystem": "WindowsIoT",
"owners@odata.bind": [
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222"
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new DeviceTemplate
{
MutualTlsOauthConfigurationId = "00001111-aaaa-2222-bbbb-3333cccc4444",
MutualTlsOauthConfigurationTenantId = "00001111-aaaa-2222-bbbb-3333cccc4445",
DeviceAuthority = "Lakeshore Retail",
Manufacturer = "Tailwind Traders",
Model = "DeepFreezerModelAB",
OperatingSystem = "WindowsIoT",
AdditionalData = new Dictionary<string, object>
{
{
"owners@odata.bind" , new List<string>
{
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222",
}
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Directory.Templates.DeviceTemplates.PostAsync(requestBody);
mgc-beta directory templates device-templates create --body '{\
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",\
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",\
"deviceAuthority": "Lakeshore Retail",\
"manufacturer": "Tailwind Traders",\
"model": "DeepFreezerModelAB",\
"operatingSystem": "WindowsIoT",\
"owners@odata.bind": [\
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222"\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDeviceTemplate()
mutualTlsOauthConfigurationId := "00001111-aaaa-2222-bbbb-3333cccc4444"
requestBody.SetMutualTlsOauthConfigurationId(&mutualTlsOauthConfigurationId)
mutualTlsOauthConfigurationTenantId := "00001111-aaaa-2222-bbbb-3333cccc4445"
requestBody.SetMutualTlsOauthConfigurationTenantId(&mutualTlsOauthConfigurationTenantId)
deviceAuthority := "Lakeshore Retail"
requestBody.SetDeviceAuthority(&deviceAuthority)
manufacturer := "Tailwind Traders"
requestBody.SetManufacturer(&manufacturer)
model := "DeepFreezerModelAB"
requestBody.SetModel(&model)
operatingSystem := "WindowsIoT"
requestBody.SetOperatingSystem(&operatingSystem)
additionalData := map[string]interface{}{
odataBind := []string {
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222",
}
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
deviceTemplates, err := graphClient.Directory().Templates().DeviceTemplates().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DeviceTemplate deviceTemplate = new DeviceTemplate();
deviceTemplate.setMutualTlsOauthConfigurationId("00001111-aaaa-2222-bbbb-3333cccc4444");
deviceTemplate.setMutualTlsOauthConfigurationTenantId("00001111-aaaa-2222-bbbb-3333cccc4445");
deviceTemplate.setDeviceAuthority("Lakeshore Retail");
deviceTemplate.setManufacturer("Tailwind Traders");
deviceTemplate.setModel("DeepFreezerModelAB");
deviceTemplate.setOperatingSystem("WindowsIoT");
HashMap<String, Object> additionalData = new HashMap<String, Object>();
LinkedList<String> ownersOdataBind = new LinkedList<String>();
ownersOdataBind.add("https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222");
additionalData.put("owners@odata.bind", ownersOdataBind);
deviceTemplate.setAdditionalData(additionalData);
DeviceTemplate result = graphClient.directory().templates().deviceTemplates().post(deviceTemplate);
const options = {
authProvider,
};
const client = Client.init(options);
const deviceTemplate = {
mutualTlsOauthConfigurationId: '00001111-aaaa-2222-bbbb-3333cccc4444',
mutualTlsOauthConfigurationTenantId: '00001111-aaaa-2222-bbbb-3333cccc4445',
deviceAuthority: 'Lakeshore Retail',
manufacturer: 'Tailwind Traders',
model: 'DeepFreezerModelAB',
operatingSystem: 'WindowsIoT',
'owners@odata.bind': [
'https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222'
]
};
await client.api('/directory/templates/deviceTemplates')
.version('beta')
.post(deviceTemplate);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\DeviceTemplate;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new DeviceTemplate();
$requestBody->setMutualTlsOauthConfigurationId('00001111-aaaa-2222-bbbb-3333cccc4444');
$requestBody->setMutualTlsOauthConfigurationTenantId('00001111-aaaa-2222-bbbb-3333cccc4445');
$requestBody->setDeviceAuthority('Lakeshore Retail');
$requestBody->setManufacturer('Tailwind Traders');
$requestBody->setModel('DeepFreezerModelAB');
$requestBody->setOperatingSystem('WindowsIoT');
$additionalData = [
'owners@odata.bind' => [
'https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222', ],
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->directory()->templates()->deviceTemplates()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
mutualTlsOauthConfigurationId = "00001111-aaaa-2222-bbbb-3333cccc4444"
mutualTlsOauthConfigurationTenantId = "00001111-aaaa-2222-bbbb-3333cccc4445"
deviceAuthority = "Lakeshore Retail"
manufacturer = "Tailwind Traders"
model = "DeepFreezerModelAB"
operatingSystem = "WindowsIoT"
"owners@odata.bind" = @(
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222"
)
}
New-MgBetaDirectoryTemplateDeviceTemplate -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.device_template import DeviceTemplate
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = DeviceTemplate(
mutual_tls_oauth_configuration_id = "00001111-aaaa-2222-bbbb-3333cccc4444",
mutual_tls_oauth_configuration_tenant_id = "00001111-aaaa-2222-bbbb-3333cccc4445",
device_authority = "Lakeshore Retail",
manufacturer = "Tailwind Traders",
model = "DeepFreezerModelAB",
operating_system = "WindowsIoT",
additional_data = {
"owners@odata_bind" : [
"https://graph.microsoft.com/beta/users/aaaaaaaa-bbbb-cccc-1111-222222222222",
],
}
)
result = await graph_client.directory.templates.device_templates.post(request_body)
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/templates/deviceTemplates/$entity",
"id": "c0ff9329-3596-4ece-8aa9-3dd23a925356",
"mutualTlsOauthConfigurationId": "00001111-aaaa-2222-bbbb-3333cccc4444",
"mutualTlsOauthConfigurationTenantId": "00001111-aaaa-2222-bbbb-3333cccc4445",
"deletedDateTime": null,
"deviceAuthority": "Lakeshore Retail",
"manufacturer": "Tailwind Traders",
"model": "DeepFreezerModelAB",
"operatingSystem": "WindowsIoT"
}