使用合作夥伴中心 API 檢查目錄專案的清查

如何檢查一組特定目錄專案的清查。

必要條件

  • 認證,如合作夥伴中心驗證所述。 此案例支援使用獨立應用程式和 App+使用者認證進行驗證。

  • 一或多個產品標識碼。 您也可以選擇指定 SKU 識別碼。

  • 驗證所提供產品/SKU 標識符所參考 SKU 庫存所需的任何其他內容。 這些需求可能會因產品/SKU 類型而有所不同,而且可以從SKU的InventoryVariables屬性判斷

C#

若要檢查清查,請使用 InventoryItem 物件建置 InventoryCheckRequest 物件,以便檢查每個專案。 然後,使用 IAggregatePartner.Extensions 存取子,將其範圍限制為 Product,然後使用 ByCountry() 方法選取國家/地區。 最後,使用 InventoryCheckRequest 物件呼叫 CheckInventory() 方法。

IAggregatePartner partnerOperations;
string customerId;
string subscriptionId;
string countryCode;
string productId;

// Build the inventory check request details object.
var inventoryCheckRequest = new InventoryCheckRequest()
{
    TargetItems = new InventoryItem[]{ new InventoryItem { ProductId = productId } },
    InventoryContext = new Dictionary<string, string>()
    {
      { "customerId", customerId },
      { "azureSubscriptionId", subscriptionId }
      { "armRegionName", armRegionName }
    }
};

// Get the inventory results.
var inventoryResults = partnerOperations.Extensions.Product.ByCountry(countryCode).CheckInventory(inventoryCheckRequest);

REST 要求

要求語法

方法 要求 URI
POST {baseURL}/v1/extensions/product/checkInventory?country={country-code} HTTP/1.1

URI 參數

使用下列查詢參數來檢查清查。

名稱 類型​​ 必要 描述
country-code string Yes 國家/地區標識碼。

要求標頭

如需詳細資訊,請參閱合作夥伴中心 REST 標頭

要求本文

清查要求詳細數據,包含包含一或多個 InventoryItem 資源的 InventoryCheckRequest 資源。

請確定要求本文中指定的 Azure 訂用帳戶已註冊並啟用以購買 Azure RI。 如需註冊程式的詳細資訊,請參閱 註冊訂 用帳戶。

要求範例

POST https://api.partnercenter.microsoft.com/v1/extensions/product/checkinventory?country=US HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: d1b1981a-e088-4610-870a-eebec96d6bcd
MS-CorrelationId: 4acb26a1-3536-4081-bc7d-092869a4961a
X-Locale: en-US
MS-PartnerCenter-Client: Partner Center .NET SDK
Content-Type: application/json

{"TargetItems":[{"ProductId":"DZH318Z0BQ3P"}],"InventoryContext":{"customerId":"d6bf25b7-e0a8-4f2d-a31b-97b55cfc774d","azureSubscriptionId":"3A231FBE-37FE-4410-93FD-730D3D5D4C75","armRegionName":"Europe"}}

重要

自 2023 年 6 月起,最新的合作夥伴中心 .NET SDK 3.4.0 版現已封存。 您可以從 GitHub 下載 SDK 版本,以及 包含實用資訊的自述檔

鼓勵合作夥伴繼續使用 合作夥伴中心 REST API

REST 回應

如果成功,回應本文會包含已填入限制詳細數據的 InventoryItem 物件集合,如果有的話。

注意

如果輸入 InventoryItem 代表目錄中找不到的專案,則不會包含在輸出集合中。

回應成功和錯誤碼

每個回應都隨附 HTTP 狀態碼,會指出成功與否以及其他的偵錯資訊。 請使用網路追蹤工具來讀取此錯誤碼、錯誤類型和其他參數。 如需完整清單,請參閱 合作夥伴中心錯誤碼

回應範例

HTTP/1.1 200 OK
Content-Length: 1021
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 4acb26a1-3536-4081-bc7d-092869a4961a
MS-RequestId: d1b1981a-e088-4610-870a-eebec96d6bcd
X-Locale: en-US
[
    {
        "productId": "DZH318Z0BQ3P",
        "skuId": "0039",
        "isRestricted": true,
        "restrictions": [
            {
                "reasonCode": "NotAvailableForSubscription",
                "description": "Restriction identified of type 'Location' with values 'japanwest'.",
                "properties": {
                    "type": "Location",
                    "values": "japanwest"
                }
            }
        ]
    },
    {
        "productId": "DZH318Z0BQ3P",
        "skuId": "0038",
        "isRestricted": true,
        "restrictions": [
            {
                "reasonCode": "NotAvailableForSubscription",
                "description": "Restriction identified of type 'Location' with values 'japanwest'.",
                "properties": {
                    "type": "Location",
                    "values": "japanwest"
                }
            }
        ]
    },
    {
        "productId": "DZH318Z0BQ3P",
        "skuId": "000S",
        "isRestricted": false,
        "restrictions": []
    },
    {
        "productId": "DZH318Z0BQ3P",
        "skuId": "0011",
        "isRestricted": false,
        "restrictions": []
    }
]