將裝置清單上傳至指定客戶的現有批次

適用於:合作夥伴中心

如何將裝置的相關信息清單上傳至指定客戶的現有批次。 這會將裝置與已建立的裝置批次產生關聯。

必要條件

C#

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

然後,使用客戶標識符呼叫 IAggregatePartner.Customers.ById 方法,以擷取指定客戶的作業介面。 接下來,使用裝置批次標識符呼叫 DeviceBatches.ById 方法,以取得指定批次作業的介面。 最後,使用裝置清單呼叫Devices.Create或 CreateAsync 方法,以將裝置新增至裝置批次。

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 Yes 識別客戶的 GUID 格式字串。
devicebatch-id string Yes 識別裝置批次的字串標識碼。

要求標頭

如需詳細資訊,請參閱合作夥伴中心 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