使用合作夥伴中心 API 檢視目錄項目的庫存
如何檢查特定目錄項目的庫存。
先決條件
合作夥伴中心驗證中所述的憑證。 此案例支援使用獨立應用程式和 App+使用者認證進行驗證。
一或多個產品標識碼。 您也可以選擇指定 SKU 識別碼。
驗證所提供的產品或 SKU ID 參考的 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 參數
使用下列查詢參數來檢查清查。
名字 | 類型 | 必填 | 描述 |
---|---|---|---|
國碼 | 字串 | 是的 | 國家/地區標識碼。 |
請求標頭
如需詳細資訊,請參閱 合作夥伴中心 REST 標頭。
請求主體
清查請求詳細信息,其中的 InventoryCheckRequest 資源包含一個或多個 InventoryItem 資源。
請確定要求本文中指定的 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: aaaa0000-bb11-2222-33cc-444444dddddd
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: aaaa0000-bb11-2222-33cc-444444dddddd
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": []
}
]