上传设备列表来为指定客户创建新批

适用于:合作伙伴中心

如何上传有关设备的信息列表,以便为指定客户创建新批。 这会在零接触部署中创建用于注册的设备批处理,并将设备和设备批处理与指定的客户相关联。

先决条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案支持使用应用凭据和用户凭据进行身份验证。 在 合作伙伴中心 API 中使用 App+User 身份验证时,请遵循安全应用模型

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

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

C#

上传设备列表以创建新的设备批处理:

  1. 实例化设备类型的新 [List/dotnet/api/system.collections.generic.list-1),并使用设备填充列表。 至少需要以下填充属性组合来标识每个设备:

  2. 实例化 DeviceBatchCreationRequest 对象,并将 BatchId 属性设置为所选的唯一名称,并将 Devices 属性设置为要上传的设备列表。

  3. 使用客户标识符调用 IAggregatePartner.Customers.ById 方法来检索指向指定客户的操作的接口,来处理设备批处理创建请求。

  4. 使用设备批处理创建请求调用 DeviceBatches.CreateCreateAsync 方法以创建批处理。

IAggregatePartner partnerOperations;
string selectedCustomerId;

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

DeviceBatchCreationRequest
    newDeviceBatch = new DeviceBatchCreationRequest
{
    BatchId = "SDKTestDeviceBatch",
    Devices = devicesToBeUploaded
};

var trackingLocation =
    partnerOperations.Customers.ById(selectedCustomerId).DeviceBatches.Create(newDeviceBatch);

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

REST 请求

请求语法

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

URI 参数

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

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

请求标头

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

请求正文

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

请求示例

POST https://api.partnercenter.microsoft.com/v1/customers/c7f3c849-129f-4b85-a96d-4f8e88b315a3/deviceBatches HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: c245d5f2-1de3-4ae0-9e42-95e38e3cb8ff
MS-CorrelationId: e3f26e6a-044f-4371-ad52-0d91ce4200be
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 340
Expect: 100-continue
Connection: Keep-Alive
{
    "BatchId": "SDKTestDeviceBatch",
    "Devices": [{
            "Id": null,
            "SerialNumber": "1R9-ZNP67",
            "ProductKey": "00329-00000-0003-AA606",
            "HardwareHash": "DummyHash123",
            "Policies": null,
            "CreatedBy": null,
            "UploadedDate": "0001-01-01T00:00:00",
            "AllowedOperations": null,
            "Attributes": {
                "ObjectType": "Device"
            }
        }
    ],
    "Attributes": {
        "ObjectType": "DeviceBatchCreationRequest"
    }
}

重要

截至 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/beba2053-5401-46ff-9223-7e841ed78fbf
MS-CorrelationId: 772871a9-399b-4f3b-b8c7-38f550e4f22a
MS-RequestId: cb82f7d6-f0d9-44d4-82f9-f6eee6e68390
MS-CV: iqOqN0FnaE2y0HcD.0
MS-ServerId: 030020525
Date: Thu, 28 Sep 2017 20:35:35 GMT