Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a new device from a deviceTemplate.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
❌ |
❌ |
❌ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Device.CreateFromOwnedTemplate |
Not available. |
Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
Application |
Not supported. |
Not supported. |
Important
In delegated scenarios with work or school accounts, the signed-in user must be assigned a supported Microsoft Entra role or a custom role with a supported role permission. The following least privileged roles are supported for this operation:
- Cloud Device Administrator
- IoT Device Administrator
- Users - owners of the device template object
Note: Users must be owner of the object.
HTTP request
POST /directory/templates/deviceTemplates/{deviceTemplateId}/createDeviceFromTemplate
Request body
In the request body, supply a JSON representation of the parameters.
The following table lists the parameters that you can use when you call this action.
Parameter |
Type |
Description |
accountEnabled |
Boolean |
true if the account is enabled; otherwise, false . The default value is true . A disabled device can't authenticate with Microsoft Entra ID. Optional. |
alternativeNames |
String collection |
A collection of ARM resource IDs associated with the device, if any. Optional. |
externalDeviceId |
String |
ID of the device in IoT registry. Must be unique within a tenant. Required. |
externalSourceName |
String |
Identifies the source name of the device. Optional. |
keyCredential |
keyCredential |
The key credential when you use self-signed certificates. Optional. |
operatingSystemVersion |
String |
The operating system version of the device specified. Optional. |
Response
If successful, this action returns a 200 OK
response code and a device object in the response body.
For more information, see Microsoft Graph error responses and resource types.
Examples
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/templates/deviceTemplates/2d62b12a-0163-457d-9796-9602e9807e1/createDeviceFromTemplate
Content-Type: application/json
{
"externalDeviceId": "2fa9424e-7ab0-4a22-8c90-2a20d15d8183",
"operatingSystemVersion": "Ubuntu 18.04",
"externalSourceName": "unknown",
"accountEnabled": false,
"alternativeNames": [
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1"
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Templates.DeviceTemplates.Item.CreateDeviceFromTemplate;
var requestBody = new CreateDeviceFromTemplatePostRequestBody
{
ExternalDeviceId = "2fa9424e-7ab0-4a22-8c90-2a20d15d8183",
OperatingSystemVersion = "Ubuntu 18.04",
ExternalSourceName = "unknown",
AccountEnabled = false,
AlternativeNames = new List<string>
{
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Templates.DeviceTemplates["{deviceTemplate-id}"].CreateDeviceFromTemplate.PostAsync(requestBody);
mgc-beta templates device-templates create-device-from-template post --device-template-id {deviceTemplate-id} --body '{\
"externalDeviceId": "2fa9424e-7ab0-4a22-8c90-2a20d15d8183",\
"operatingSystemVersion": "Ubuntu 18.04",\
"externalSourceName": "unknown",\
"accountEnabled": false,\
"alternativeNames": [\
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1"\
]\
}\
'
// 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"
graphtemplates "github.com/microsoftgraph/msgraph-beta-sdk-go/templates"
//other-imports
)
requestBody := graphtemplates.NewCreateDeviceFromTemplatePostRequestBody()
externalDeviceId := "2fa9424e-7ab0-4a22-8c90-2a20d15d8183"
requestBody.SetExternalDeviceId(&externalDeviceId)
operatingSystemVersion := "Ubuntu 18.04"
requestBody.SetOperatingSystemVersion(&operatingSystemVersion)
externalSourceName := "unknown"
requestBody.SetExternalSourceName(&externalSourceName)
accountEnabled := false
requestBody.SetAccountEnabled(&accountEnabled)
alternativeNames := []string {
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1",
}
requestBody.SetAlternativeNames(alternativeNames)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createDeviceFromTemplate, err := graphClient.Templates().DeviceTemplates().ByDeviceTemplateId("deviceTemplate-id").CreateDeviceFromTemplate().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.templates.devicetemplates.item.createdevicefromtemplate.CreateDeviceFromTemplatePostRequestBody createDeviceFromTemplatePostRequestBody = new com.microsoft.graph.beta.templates.devicetemplates.item.createdevicefromtemplate.CreateDeviceFromTemplatePostRequestBody();
createDeviceFromTemplatePostRequestBody.setExternalDeviceId("2fa9424e-7ab0-4a22-8c90-2a20d15d8183");
createDeviceFromTemplatePostRequestBody.setOperatingSystemVersion("Ubuntu 18.04");
createDeviceFromTemplatePostRequestBody.setExternalSourceName("unknown");
createDeviceFromTemplatePostRequestBody.setAccountEnabled(false);
LinkedList<String> alternativeNames = new LinkedList<String>();
alternativeNames.add("/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1");
createDeviceFromTemplatePostRequestBody.setAlternativeNames(alternativeNames);
Device result = graphClient.templates().deviceTemplates().byDeviceTemplateId("{deviceTemplate-id}").createDeviceFromTemplate().post(createDeviceFromTemplatePostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const device = {
externalDeviceId: '2fa9424e-7ab0-4a22-8c90-2a20d15d8183',
operatingSystemVersion: 'Ubuntu 18.04',
externalSourceName: 'unknown',
accountEnabled: false,
alternativeNames: [
'/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1'
]
};
await client.api('/templates/deviceTemplates/2d62b12a-0163-457d-9796-9602e9807e1/createDeviceFromTemplate')
.version('beta')
.post(device);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Templates\DeviceTemplates\Item\CreateDeviceFromTemplate\CreateDeviceFromTemplatePostRequestBody;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateDeviceFromTemplatePostRequestBody();
$requestBody->setExternalDeviceId('2fa9424e-7ab0-4a22-8c90-2a20d15d8183');
$requestBody->setOperatingSystemVersion('Ubuntu 18.04');
$requestBody->setExternalSourceName('unknown');
$requestBody->setAccountEnabled(false);
$requestBody->setAlternativeNames(['/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1', ]);
$result = $graphServiceClient->templates()->deviceTemplates()->byDeviceTemplateId('deviceTemplate-id')->createDeviceFromTemplate()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.templates.devicetemplates.item.create_device_from_template.create_device_from_template_post_request_body import CreateDeviceFromTemplatePostRequestBody
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateDeviceFromTemplatePostRequestBody(
external_device_id = "2fa9424e-7ab0-4a22-8c90-2a20d15d8183",
operating_system_version = "Ubuntu 18.04",
external_source_name = "unknown",
account_enabled = False,
alternative_names = [
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1",
],
)
result = await graph_client.templates.device_templates.by_device_template_id('deviceTemplate-id').create_device_from_template.post(request_body)
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "06d59f74-dbf3-432a-9971-c5f60374e4f0",
"accountEnabled": false,
"alternativeNames": [
"/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/testrg/providers/microsoft.deviceregistry/assets/asset1"
],
"deviceId": "c6ca2657-8685-4398-9edc-a6a603f177b3",
"displayName": "2fa9424e-7ab0-4a22-8c90-2a20d15d8183",
"externalSourceName": "unknown",
"manufacturer": "IoT Device Template Manufacturer",
"model": "IoT Device Template Model",
"operatingSystem": "WindowsIoT",
"operatingSystemVersion": "Ubuntu 18.04",
"physicalIds": [
"[EXTID]:2fa9424e-7ab0-4a22-8c90-2a20d15d8183"
],
"profileType": "IoT",
"sourceType": "External",
"alternativeSecurityIds": [
{
"type": 2,
"identityProvider": null,
"key": "WAA1ADAAOQA6ADwAVQB..."
}
]
}