Update a list of devices with a policy
Applies to: Partner Center
How to update a list of devices with a configuration policy for the specified customer.
Prerequisites
Credentials as described in Partner Center authentication. This scenario supports authentication with both standalone App and App+User credentials.
A customer ID (
customer-tenant-id
). If you don't know the customer's ID, you can look it up in Partner Center by selecting the Customers workspace, then the customer from the customer list, then Account. On the customer's Account page, look for the Microsoft ID in the Customer Account Info section. The Microsoft ID is the same as the customer ID (customer-tenant-id
).The policy identifier.
The device identifiers of the devices to update.
C#
To update a list of devices with the specified configuration policy, first, instantiate a [List/dotnet/api/system.collections.generic.list-1) of type [KeyValuePair/dotnet/api/system.collections.generic.keyvaluepair-2)(PolicyCategory,string) and add the policy to apply, as shown in the following code example. You'll need the policy identifier of the policy.
Then, create a list of Device objects to be updated with the policy, specifying the device identifier and the list that contains the policy to apply, for each device. Next, instantiate a DevicePolicyUpdateRequest object and set the Devices property to the list of device objects.
To process the device policy update request, call the IAggregatePartner.Customers.ById method with the customer identifier to retrieve an interface to operations on the specified customer. Then, retrieve the DevicePolicy property to get an interface to customer device collection operations. Finally, call the Update method with the DevicePolicyUpdateRequest object to update the devices with the policy.
IAggregatePartner partnerOperations;
string selectedCustomerId;
string selectedConfigurationPolicyId;
string selectedDeviceId;
// Indicate the policy to apply to the list of devices.
List<KeyValuePair<PolicyCategory, string>>
policyToBeAdded = new List<KeyValuePair<PolicyCategory, string>>
{
new KeyValuePair<PolicyCategory, string>
(PolicyCategory.OOBE, selectedConfigurationPolicyId)
};
// Create a list of devices to be updated with a policy.
List<Device> devices = new List<Device>
{
new Device
{
Id = selectedDeviceId,
Policies=policyToBeAdded
}
};
// Instantiate a DevicePolicyUpdateRequest object.
DevicePolicyUpdateRequest
devicePolicyUpdateRequest = new DevicePolicyUpdateRequest
{
Devices = devices
};
// Process the DevicePolicyUpdateRequest.
var trackingLocation =
partnerOperations.Customers.ById(selectedCustomerId).DevicePolicy.Update(devicePolicyUpdateRequest);
Sample: Console test app. Project: Partner Center SDK Samples Class: UpdateDevicesPolicy.cs
REST request
Request syntax
Method | Request URI |
---|---|
PATCH | {baseURL}/v1/customers/{customer-id}/DevicePolicyUpdates HTTP/1.1 |
URI parameter
Use the following path parameters when creating the request.
Name | Type | Required | Description |
---|---|---|---|
customer-id | string | Yes | A GUID-formatted string that identifies the customer. |
Request headers
For more information, see Partner Center REST headers.
Request body
The request body must contain a DevicePolicyUpdateRequest resource.
Request example
PATCH https://api.partnercenter.microsoft.com/v1/customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/DevicePolicyUpdates HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 1b658428-5afa-46d4-af86-c9c6af5634e2
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 363
Expect: 100-continue
Connection: Keep-Alive
{
"Devices": [{
"Id": "9993-8627-3608-6844-6369-4361-72",
"SerialNumber": null,
"ProductKey": null,
"HardwareHash": null,
"Policies": [{
"Key": "o_o_b_e",
"Value": "15a04610-9229-4e80-94e0-0e826a09c9e2"
}
],
"CreatedBy": null,
"UploadedDate": "0001-01-01T00:00:00",
"AllowedOperations": null,
"Attributes": {
"ObjectType": "Device"
}
}
],
"Attributes": {
"ObjectType": "DevicePolicyUpdateRequest"
}
}
Important
As of June 2023, the latest Partner Center .NET SDK release 3.4.0 is now archived. You can download the SDK release from GitHub, along with a readme file that contains useful information.
Partners are encouraged to continue to use the Partner Center REST APIs.
REST response
If successful, the response contains a Location header that has a URI that can be used to retrieve the status of this batch process. Save this URI for use with other related REST APIs.
Response success and error codes
Each response comes with an HTTP status code that indicates success or failure and additional debugging information. Use a network trace tool to read this code, error type, and additional parameters. For the full list, see Partner Center REST error codes.
Response example
HTTP/1.1 202 Accepted
Content-Length: 0
Location: /customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/batchJobStatus/a15f3996-620a-4404-9f1f-4c2de78de0de
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 1b658428-5afa-46d4-af86-c9c6af5634e2
MS-CV: rCXyd8Z/lUSxUd0P.0
MS-ServerId: 020021921
Date: Thu, 28 Sep 2017 21:33:05 GMT