上傳裝置清單,為指定的客戶建立新的批次

適用於:合作夥伴中心

如何上傳裝置的相關信息清單,為指定的客戶建立新的批次。 這會在零接觸部署中建立註冊的裝置批次,並將裝置和裝置批次與指定的客戶產生關聯。

必要條件

C#

若要上傳裝置清單以建立新的裝置批次:

  1. 具現化類型 Device 的新 [List/dotnet/api/system.collections.generic.list-1),並使用裝置填入清單。 至少需要下列填入屬性組合,才能識別每個裝置:

  2. 具現化 DeviceBatchCreationRequest 物件,並將 BatchId 屬性設定為您選擇的唯一名稱,並將 Devices 屬性設定為要上傳的裝置清單。

  3. 使用客戶標識符呼叫 IAggregatePartner.Customers.ById 方法來處理裝置批次建立要求,以擷取指定客戶的作業介面。

  4. 使用裝置批次建立要求呼叫 DeviceBatches.Create 或 CreateAsync 方法,以建立批次。

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 Yes 識別客戶的 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