サブスクリプションのアドオンを購入する

適用対象: パートナー センター | 21Vianet が運営するパートナー センター | Microsoft Cloud for US Government のパートナー センター

既存のサブスクリプションにアドオンを購入する方法。

前提条件

  • パートナー センターの認証に関するページで説明している資格情報。 このシナリオでは、スタンドアロンの App と App+User の両方の資格情報を使用した認証がサポートされています。

  • 顧客 ID です (customer-tenant-id)。 顧客の ID がわからない場合は、 パートナー センター で [顧客] ワークスペースを選択し、 次に顧客 の一覧から [顧客]、[ アカウント] の順に選択して、その ID を検索できます。 お客様のアカウント ページで、 [顧客のアカウント情報] セクションの Microsoft ID を探します。 Microsoft ID は、顧客 ID (customer-tenant-id) と同じです。

  • サブスクリプション ID。 これは、アドオン オファーを購入する既存のサブスクリプションです。

  • 購入するアドオン オファーを識別するオファー ID。

コードを使用したアドオンの購入

サブスクリプションにアドオンを購入すると、アドオンの注文で元のサブスクリプション注文が更新されます。 次の例では、customerId は顧客 ID、subscriptionId はサブスクリプション ID、addOnOfferId はアドオンのオファー ID です。

次に手順を示します。

  1. サブスクリプションの操作へのインターフェイスを取得します。

    var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId);
    
  2. そのインターフェイスを使用して、サブスクリプション オブジェクトをインスタンス化します。 これにより、注文 ID を含む親サブスクリプションの詳細が取得されます。

    var parentSubscription = subscriptionOperations.Get();
    
  3. 新しい Order オブジェクトをインスタンス化します。 この注文インスタンスは、サブスクリプションの購入に使用された元の注文を更新するために使用されます。 アドオンを表す注文に 1 行の項目を追加します。

    var orderToUpdate = new Order()
    {
        ReferenceCustomerId = customerId,
        LineItems = new List<OrderLineItem>()
        {
            new OrderLineItem()
            {
                LineItemNumber = 0,
                OfferId = addOnOfferId,
                FriendlyName = "Some friendly name",
                Quantity = 2,
                ParentSubscriptionId = subscriptionId
            }
        }
    };
    
  4. アドオンの新しい注文でサブスクリプションの元の注文を更新します。

    Order updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(parentSubscription.OrderId).Patch(orderToUpdate);
    

C#

アドオンを購入するには、まず、顧客 ID を使用して IAggregatePartner.Customers.ById メソッドを呼び出して顧客を識別し、 Subscriptions.ById メソッドを呼び出して、サブスクリプション操作へのインターフェイスを取得して、アドオン オファーを持つサブスクリプションを識別します。 その インターフェイス を使用して 、Get を呼び出してサブスクリプションの詳細を取得します。 サブスクリプションの詳細には、アドオンで更新する注文であるサブスクリプション注文の注文 ID が含まれます。

次に、次のコード スニペットに示すように、新しい Order オブジェクトをインスタンス化し、アドオンを識別するための情報を含む 1 つの LineItem インスタンスを設定します。 この新しいオブジェクトを使用して、アドオンでサブスクリプションの順序を更新します。 最後に、 Patch メソッドを呼び出してサブスクリプションの注文を更新します。最初に IAggregatePartner.Customers.ById で顧客を識別し、 Orders.ById を使用して注文を識別します。

// IAggregatePartner partnerOperations;
// string customerId;
// string subscriptionId;
// string addOnOfferId;

// Get an interface to the operations for the subscription.
var subscriptionOperations = partnerOperations.Customers.ById(customerId).Subscriptions.ById(subscriptionId);

// Get the parent subscription details.
var parentSubscription = subscriptionOperations.Get();

// In order to buy an add-on subscription for this offer, we need to patch/update the order through which the base offer was purchased
// by creating an order object with a single line item which represents the add-on offer purchase.
var orderToUpdate = new Order()
{
    ReferenceCustomerId = customerId,
    LineItems = new List<OrderLineItem>()
    {
        new OrderLineItem()
        {
            LineItemNumber = 0,
            OfferId = addOnOfferId,
            FriendlyName = "Some friendly name",
            Quantity = 2,
            ParentSubscriptionId = subscriptionId
        }
    }
};

// Update the order to apply the add on purchase.
Order updatedOrder = partnerOperations.Customers.ById(customerId).Orders.ById(parentSubscription.OrderId).Patch(orderToUpdate);

サンプル: コンソール テスト アプリプロジェクト: パートナー センター SDK サンプル クラス: AddSubscriptionAddOn.cs

REST 要求

要求の構文

認証方法 要求 URI
PATCH {baseURL}/v1/customers/{customer-tenant-id}/orders/{order-id} HTTP/1.1

URI パラメーター

顧客と注文を識別するには、次のパラメーターを使用します。

名前 Type 必須 説明
customer-tenant-id guid Y 値は、顧客を識別する GUID 形式 の customer-tenant-id です。
order-id guid Y 注文識別子。

要求ヘッダー

詳細については、「パートナー センター REST ヘッダー」を参照してください。

[要求本文]

次の表では、要求本文のプロパティについて説明します。

Order

名前 Type 必須 説明
Id string N 注文 ID。
ReferenceCustomerId string Y 顧客 ID。
LineItems オブジェクトの配列 Y OrderLineItem オブジェクトの配列。
CreationDate string N 注文が作成された日付 (日付/時刻形式)。
属性 object N "ObjectType": "Order" が含まれます。

OrderLineItem

名前 Type 必須 説明
LineItemNumber number Y 0 から始まる明細番号。
OfferId string Y アドオンのオファー ID。
SubscriptionId string N 購入したアドオン サブスクリプションの ID。
ParentSubscriptionId string Y アドオン オファーがある親サブスクリプションの ID。
FriendlyName string N この品目のフレンドリ名。
数量 数値 Y ライセンス数。
PartnerIdOnRecord string N レコードのパートナーの PartnerID。
属性 object N "ObjectType": "OrderLineItem" が含まれます。

要求の例

PATCH https://api.partnercenter.microsoft.com/v1/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/orders/CF3B0E37-BE0B-4CDD-B584-D1A97D98A922 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 17a2658e-d2cc-439b-a2f0-2aefd9344fbc
MS-CorrelationId: 60efdd24-17ef-4080-9b02-4fc315f916ff
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 414
Expect: 100-continue

{
    "Id": null,
    "ReferenceCustomerId": "4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04",
    "LineItems": [{
            "LineItemNumber": 0,
            "OfferId": "2828BE95-46BA-4F91-B2FD-0BEF192ECF60",
            "SubscriptionId": null,
            "ParentSubscriptionId": "1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
            "FriendlyName": "Some friendly name",
            "Quantity": 2,
            "PartnerIdOnRecord": null,
            "Attributes": {
                "ObjectType": "OrderLineItem"
            }
        }
    ],
    "CreationDate": null,
    "Attributes": {
        "ObjectType": "Order"
    }
}

REST 応答

成功した場合、このメソッドは応答本文で更新されたサブスクリプションの順序を返します。

応答の成功とエラーのコード

各応答には、成功または失敗を示す HTTP ステータス コードと、追加のデバッグ情報が付属しています。 このコード、エラーの種類、追加のパラメーターを読み取るには、ネットワーク トレース ツールを使用します。 完全な一覧については、「 パートナー センターのエラー コード」を参照してください。

応答の例

HTTP/1.1 200 OK
Content-Length: 1135
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 60efdd24-17ef-4080-9b02-4fc315f916ff
MS-RequestId: 17a2658e-d2cc-439b-a2f0-2aefd9344fbc
MS-CV: WtFy3zI8V0u2lnT9.0
MS-ServerId: 020021921
Date: Wed, 25 Jan 2017 23:01:08 GMT

{
    "id": "cf3b0e37-be0b-4cdd-b584-d1a97d98a922",
    "referenceCustomerId": "4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04",
    "billingCycle": "none",
    "lineItems": [{
            "lineItemNumber": 0,
            "offerId": "195416C1-3447-423A-B37B-EE59A99A19C4",
            "subscriptionId": "1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
            "friendlyName": "new offer purchase",
            "quantity": 5,
            "links": {
                "subscription": {
                    "uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/subscriptions/1C2B75C1-74A5-472A-A729-7F8CEFC477F9",
                    "method": "GET",
                    "headers": []
                }
            }
        }, {
            "lineItemNumber": 1,
            "offerId": "2828BE95-46BA-4F91-B2FD-0BEF192ECF60",
            "subscriptionId": "968BA1CF-C146-4ADF-A300-308DCF718EEE",
            "friendlyName": "Some friendly name",
            "quantity": 2,
            "links": {
                "subscription": {
                    "uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/subscriptions/968BA1CF-C146-4ADF-A300-308DCF718EEE",
                    "method": "GET",
                    "headers": []
                }
            }
        }
    ],
    "creationDate": "2017-01-25T14:53:12.093-08:00",
    "links": {
        "self": {
            "uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/orders/cf3b0e37-be0b-4cdd-b584-d1a97d98a922",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "etag": "eyJpZCI6ImNmM2IwZTM3LWJlMGItNGNkZC1iNTg0LWQxYTk3ZDk4YTkyMiIsInZlcnNpb24iOjJ9",
        "objectType": "Order"
    }
}