将设备列表上传到指定客户的现有批

适用于:合作伙伴中心

如何将有关设备的信息列表上传到指定客户的现有批处理。 这会将设备与已创建的设备批处理相关联。

先决条件

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

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

  • 设备批处理标识符。

  • 提供有关单个设备的信息的设备资源列表。

C#

若要将设备列表上传到现有设备批处理,请先实例化设备类型的新 [List/dotnet/api/system.collections.generic.list-1),并使用设备填充列表。 至少需要以下填充属性组合来标识每个设备:

然后,使用客户标识符调用 IAggregatePartner.Customers.ById 方法,以检索对指定客户的操作的接口。 接下来,使用设备批标识符调用 DeviceBatches.ById 方法,以获取指定批处理操作的接口。 最后,使用设备列表调用 Devices.CreateCreateAsync 方法,以将设备添加到设备批处理。

IAggregatePartner partnerOperations;
string selectedCustomerId;
string selectedDeviceBatchId;

List<Device> devicesToBeUploaded = new List<Device>
{
    new Device
    {
        HardwareHash = "DummyHash1234",
        ProductKey = "00329-00000-0003-AA606",
        SerialNumber = "2R9-ZNP67"
    },

    new Device
    {
        HardwareHash = "DummyHash12345",
        ProductKey = "00329-00000-0003-AA606",
        SerialNumber = "2R9-ZNP67"
    }
};

var trackingLocation =
    partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.ById(selectedDeviceBatchId).Devices.Create(devicesToBeUploaded);

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

REST 请求

请求语法

方法 请求 URI
POST {baseURL}/v1/customers/{customer-id}/deviceBatches/{devicebatch-id}/devices HTTP/1.1

URI 参数

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

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

请求标头

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

请求正文

请求正文必须包含 Device 对象的数组。 接受用于标识设备的以下字段组合:

  • hardwareHash + productKey。
  • hardwareHash + serialNumber。
  • hardwareHash + productKey + serialNumber。
  • 仅 hardwareHash。
  • 仅限 productKey。
  • serialNumber + oemManufacturerName + modelName。

请求示例

POST https://api.partnercenter.microsoft.com/v1/customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/deviceBatches/Test/devices HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: e286d69b-7f5f-4098-8999-21d3b54e4e47
MS-CorrelationId: 772871a9-399b-4f3b-b8c7-38f550e4f22a
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 482
Expect: 100-continue

[{
        "Id": null,
        "SerialNumber": "2R9-ZNP67",
        "ProductKey": "00329-00000-0003-AA606",
        "HardwareHash": "DummyHash1234",
        "Policies": null,
        "CreatedBy": null,
        "UploadedDate": "0001-01-01T00:00:00",
        "AllowedOperations": null,
        "Attributes": {
            "ObjectType": "Device"
        }
    }, {
        "Id": null,
        "SerialNumber": "2R9-ZNP67",
        "ProductKey": "00329-00000-0003-AA606",
        "HardwareHash": "DummyHash12345",
        "Policies": null,
        "CreatedBy": null,
        "UploadedDate": "0001-01-01T00:00:00",
        "AllowedOperations": null,
        "Attributes": {
            "ObjectType": "Device"
        }
    }
]

重要

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

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

REST 响应

如果成功,响应将包含 可用于检索设备上传状态的 URI 的位置 标头。 保存此 URI 以与其他相关的 REST API 一起使用。

响应的成功和错误代码

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

响应示例

HTTP/1.1 202 Accepted
Content-Length: 0
Location: /customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/batchJobStatus/16c00110-e79a-433d-aa28-f69dd60df671
MS-CorrelationId: 772871a9-399b-4f3b-b8c7-38f550e4f22a
MS-RequestId: e286d69b-7f5f-4098-8999-21d3b54e4e47
MS-CV: OBkGN9pSN0a5xvua.0
MS-ServerId: 101112012
Date: Thu, 28 Sep 2017 20:08:46 GMT