使用策略更新设备列表

适用于:合作伙伴中心

如何使用指定客户的配置策略更新设备列表。

先决条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+User 凭据进行身份验证。

  • 客户 ID (customer-tenant-id)。 如果不知道客户的 ID,可以通过选择“客户”工作区,然后从客户列表中选择客户,然后选择“帐户”,在合作伙伴中心查找该 ID。 在客户的“帐户”页上,在“客户帐户信息”部分查找 Microsoft ID Microsoft ID 与客户 ID (customer-tenant-id) 相同。

  • 策略标识符。

  • 要更新的设备的设备标识符。

C#

若要更新具有指定配置策略的设备列表,请先实例化 [KeyValuePair/dotnet/dotnet/api/system.collections.generic.list-1) 类型的 [List/dotnet/api/system.collections.generic.keyvaluepair-2)(PolicyCategory,string)并添加要应用的策略,如以下代码示例所示。 需要策略的策略标识符。

然后,创建一个使用策略更新的设备对象列表,并指定设备标识符和包含要应用的策略的列表,以便为每个设备应用策略。 接下来,实例化 DevicePolicyUpdateRequest 对象,并将 Devices 属性设置为设备对象列表。

若要处理设备策略更新请求,请使用客户标识符调用 IAggregatePartner.Customers.ById 方法,以检索指向指定客户的操作的接口。 然后,检索 DevicePolicy 属性以获取客户设备收集操作的接口。 最后,使用 DevicePolicyUpdateRequest 对象调用 Update 方法,以使用策略更新设备。

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);

示例控制台测试应用项目:合作伙伴中心 SDK 示例 :UpdateDevicesPolicy.cs

REST 请求

请求语法

方法 请求 URI
PATCH {baseURL}/v1/customers/{customer-id}/DevicePolicy汇报 HTTP/1.1

URI 参数

创建请求时,请使用以下路径参数。

名称 类型​​ 必需 说明
customer-id string 一个 GUID 格式的字符串,用于标识客户。

请求标头

有关详细信息,请参阅合作伙伴中心 REST 标头

请求正文

请求正文必须包含 DevicePolicyUpdateRequest 资源。

请求示例

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: 49b1e7b2-82e7-4403-b63b-8765269b448d
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"
    }
}

重要

截至 2023 年 6 月,最新的合作伙伴中心 .NET SDK 版本 3.4.0 现已存档。 可以从 GitHub 下载 SDK 版本,以及包含有用信息的自述文件

建议合作伙伴继续使用合作伙伴中心 REST API

REST 响应

如果成功,响应将包含 可用于检索此批处理状态的 URI 的 Location 标头。 保存此 URI 以与其他相关的 REST API 一起使用。

响应的成功和错误代码

每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 如需完整列表,请参阅合作伙伴中心 REST 错误代码

响应示例

HTTP/1.1 202 Accepted
Content-Length: 0
Location: /customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/batchJobStatus/a15f3996-620a-4404-9f1f-4c2de78de0de
MS-CorrelationId: 49b1e7b2-82e7-4403-b63b-8765269b448d
MS-RequestId: 1b658428-5afa-46d4-af86-c9c6af5634e2
MS-CV: rCXyd8Z/lUSxUd0P.0
MS-ServerId: 020021921
Date: Thu, 28 Sep 2017 21:33:05 GMT