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.
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) |
Directory.AccessAsUser.All |
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.
- Intune Administrator
- Windows 365 Administrator
HTTP request
POST /devices
Request body
In the request body, supply a JSON representation of device object.
Since the device resource supports extensions, you can use the POST
operation and add custom properties with your own data to the device instance while creating it.
Response
If successful, this method returns 201 Created
response code and device object in the response body.
Example
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/devices
Content-type: application/json
{
"accountEnabled": true,
"alternativeSecurityIds": [
{
"type": 99,
"identityProvider": "identityProvider-value",
"key": "base64Y3YxN2E1MWFlYw=="
}
],
"approximateLastSignInDateTime": "2016-10-19T10:37:00Z",
"deviceId": "deviceId-value",
"deviceMetadata": "deviceMetadata-value",
"deviceVersion": 99
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Device
{
AccountEnabled = true,
AlternativeSecurityIds = new List<AlternativeSecurityId>
{
new AlternativeSecurityId
{
Type = 99,
IdentityProvider = "identityProvider-value",
Key = Convert.FromBase64String("base64Y3YxN2E1MWFlYw=="),
},
},
ApproximateLastSignInDateTime = DateTimeOffset.Parse("2016-10-19T10:37:00Z"),
DeviceId = "deviceId-value",
DeviceMetadata = "deviceMetadata-value",
DeviceVersion = 99,
};
// 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);
mgc-beta devices create --body '{\
"accountEnabled": true,\
"alternativeSecurityIds": [\
{\
"type": 99,\
"identityProvider": "identityProvider-value",\
"key": "base64Y3YxN2E1MWFlYw=="\
}\
],\
"approximateLastSignInDateTime": "2016-10-19T10:37:00Z",\
"deviceId": "deviceId-value",\
"deviceMetadata": "deviceMetadata-value",\
"deviceVersion": 99\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
"time"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDevice()
accountEnabled := true
requestBody.SetAccountEnabled(&accountEnabled)
alternativeSecurityId := graphmodels.NewAlternativeSecurityId()
type := int32(99)
alternativeSecurityId.SetType(&type)
identityProvider := "identityProvider-value"
alternativeSecurityId.SetIdentityProvider(&identityProvider)
key := []byte("base64Y3YxN2E1MWFlYw==")
alternativeSecurityId.SetKey(&key)
alternativeSecurityIds := []graphmodels.AlternativeSecurityIdable {
alternativeSecurityId,
}
requestBody.SetAlternativeSecurityIds(alternativeSecurityIds)
approximateLastSignInDateTime , err := time.Parse(time.RFC3339, "2016-10-19T10:37:00Z")
requestBody.SetApproximateLastSignInDateTime(&approximateLastSignInDateTime)
deviceId := "deviceId-value"
requestBody.SetDeviceId(&deviceId)
deviceMetadata := "deviceMetadata-value"
requestBody.SetDeviceMetadata(&deviceMetadata)
deviceVersion := int32(99)
requestBody.SetDeviceVersion(&deviceVersion)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
devices, err := graphClient.Devices().Post(context.Background(), requestBody, nil)
// 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(true);
LinkedList<AlternativeSecurityId> alternativeSecurityIds = new LinkedList<AlternativeSecurityId>();
AlternativeSecurityId alternativeSecurityId = new AlternativeSecurityId();
alternativeSecurityId.setType(99);
alternativeSecurityId.setIdentityProvider("identityProvider-value");
byte[] key = Base64.getDecoder().decode("base64Y3YxN2E1MWFlYw==");
alternativeSecurityId.setKey(key);
alternativeSecurityIds.add(alternativeSecurityId);
device.setAlternativeSecurityIds(alternativeSecurityIds);
OffsetDateTime approximateLastSignInDateTime = OffsetDateTime.parse("2016-10-19T10:37:00Z");
device.setApproximateLastSignInDateTime(approximateLastSignInDateTime);
device.setDeviceId("deviceId-value");
device.setDeviceMetadata("deviceMetadata-value");
device.setDeviceVersion(99);
Device result = graphClient.devices().post(device);
const options = {
authProvider,
};
const client = Client.init(options);
const device = {
accountEnabled: true,
alternativeSecurityIds: [
{
type: 99,
identityProvider: 'identityProvider-value',
key: 'base64Y3YxN2E1MWFlYw=='
}
],
approximateLastSignInDateTime: '2016-10-19T10:37:00Z',
deviceId: 'deviceId-value',
deviceMetadata: 'deviceMetadata-value',
deviceVersion: 99
};
await client.api('/devices')
.version('beta')
.post(device);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Device;
use Microsoft\Graph\Beta\Generated\Models\AlternativeSecurityId;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Device();
$requestBody->setAccountEnabled(true);
$alternativeSecurityIdsAlternativeSecurityId1 = new AlternativeSecurityId();
$alternativeSecurityIdsAlternativeSecurityId1->setType(99);
$alternativeSecurityIdsAlternativeSecurityId1->setIdentityProvider('identityProvider-value');
$alternativeSecurityIdsAlternativeSecurityId1->setKey(\GuzzleHttp\Psr7\Utils::streamFor(base64_decode('base64Y3YxN2E1MWFlYw==')));
$alternativeSecurityIdsArray []= $alternativeSecurityIdsAlternativeSecurityId1;
$requestBody->setAlternativeSecurityIds($alternativeSecurityIdsArray);
$requestBody->setApproximateLastSignInDateTime(new \DateTime('2016-10-19T10:37:00Z'));
$requestBody->setDeviceId('deviceId-value');
$requestBody->setDeviceMetadata('deviceMetadata-value');
$requestBody->setDeviceVersion(99);
$result = $graphServiceClient->devices()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
accountEnabled = $true
alternativeSecurityIds = @(
@{
type = 99
identityProvider = "identityProvider-value"
key = [System.Text.Encoding]::ASCII.GetBytes("base64Y3YxN2E1MWFlYw==")
}
)
approximateLastSignInDateTime = [System.DateTime]::Parse("2016-10-19T10:37:00Z")
deviceId = "deviceId-value"
deviceMetadata = "deviceMetadata-value"
deviceVersion = 99
}
New-MgBetaDevice -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 import Device
from msgraph_beta.generated.models.alternative_security_id import AlternativeSecurityId
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Device(
account_enabled = True,
alternative_security_ids = [
AlternativeSecurityId(
type = 99,
identity_provider = "identityProvider-value",
key = base64.urlsafe_b64decode("base64Y3YxN2E1MWFlYw=="),
),
],
approximate_last_sign_in_date_time = "2016-10-19T10:37:00Z",
device_id = "deviceId-value",
device_metadata = "deviceMetadata-value",
device_version = 99,
)
result = await graph_client.devices.post(request_body)
In the request body, supply a JSON representation of device object.
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
{
"accountEnabled": true,
"alternativeSecurityIds": [
{
"type": 99,
"identityProvider": "identityProvider-value",
"key": "base64Y3YxN2E1MWFlYw=="
}
],
"approximateLastSignInDateTime": "2016-10-19T10:37:00Z",
"deviceId": "deviceId-value",
"deviceMetadata": "deviceMetadata-value",
"deviceVersion": 99
}
Related content