使用合作伙伴中心 API 检查目录项的清单

如何检查一组特定目录项的清单。

先决条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+User 凭据进行身份验证。

  • 一个或多个产品 ID。 (可选)还可以指定 SKU ID。

  • 验证所提供的产品/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/检查Inventory?country={country-code} HTTP/1.1

URI 参数

使用以下查询参数检查清单。

名称 类型​​ 必需 说明
country-code string 国家/地区 ID。

请求标头

有关详细信息,请参阅合作伙伴中心 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": []
    }
]