共用方式為


更新購物車

如何在購物車中更新客戶的訂單。

請注意,購物車會從初始建立起七天到期。

必要條件

C#

若要更新客戶的訂單,請使用 Get() 方法來取得購物車,方法是使用 ById() 函式傳遞客戶和購物車標識符。 對購物車進行必要的變更。 現在,使用 ById() 方法來使用客戶和購物車標識碼來呼叫 Put 方法。

最後,呼叫 Put()PutAsync() 方法來建立順序。

IAggregatePartner partnerOperations;
string customerId;
string cartId;

var cart = partnerOperations.Customers.ById(customerId).Cart.ById(cartId).Get();

cart.LineItems.ToArray()[0].Quantity++;

var updatedCart = partnerOperations.Customers.ById(customerId).Cart.ById(cartId).Put(cart);

若要完成證明並包含其他轉銷商,請參閱下列範例。

API 範例 - 取出購物車

{
    "orders": [
        {
            "id": "f76c6b7f449d",
            "alternateId": "f76c6b7f449d",
            "referenceCustomerId": "f81d98dd-c2f4-499e-a194-5619e260344e",
            "billingCycle": "monthly",
            "currencyCode": "USD",
            "currencySymbol": "$",
            "lineItems": [
                {
                    "lineItemNumber": 0,
                    "offerId": "CFQ7TTC0LH0Z:0001:CFQ7TTC0K18P",
                    "subscriptionId": "ebc0beef-7ffb-4044-c074-16f324432139",
                    "termDuration": "P1M",
                    "transactionType": "New",
                    "friendlyName": "AI Builder Capacity add-on",
                    "quantity": 1,
                    "links": {
                        "product": {
                            "uri": "/products/CFQ7TTC0LH0Z?country=US",
                            "method": "GET",
                            "headers": []
                        },
                        "sku": {
                            "uri": "/products/CFQ7TTC0LH0Z/skus/0001?country=US",
                            "method": "GET",
                            "headers": []
                        },
                        "availability": {
                            "uri": "/products/CFQ7TTC0LH0Z/skus/0001/availabilities/CFQ7TTC0K18P?country=US",
                            "method": "GET",
                            "headers": []
                        }
                    }
                },
                {
                    "lineItemNumber": 1,
                    "offerId": "CFQ7TTC0LFLS:0002:CFQ7TTC0KDLJ",
                    "subscriptionId": "261bac40-7d88-4327-dfa3-dacd09222d62",
                    "termDuration": "P1Y",
                    "transactionType": "New",
                    "friendlyName": "Azure Active Directory Premium P1",
                    "quantity": 2,
                    "partnerIdOnRecord": "517285",
                    "additionalPartnerIdsOnRecord": 
                        "5357564",
                        "5357563"
                    ],
                 
   "links": {
                        "product": {
                            "uri": "/products/CFQ7TTC0LFLS?country=US",
                            "method": "GET",
                            "headers": []
                        },
                        "sku": {
                            "uri": "/products/CFQ7TTC0LFLS/skus/0002?country=US",
                            "method": "GET",
                            "headers": []
                        },
                        "availability": {
                            "uri": "/products/CFQ7TTC0LFLS/skus/0002/availabilities/CFQ7TTC0KDLJ?country=US",
                            "method": "GET",
                            "headers": []
                        }
                    }
                }
            ],
            "creationDate": "2021-08-18T07:52:23.1921872Z",
            "status": "pending",
            "transactionType": "UserPurchase",
            "links": {
                "self": {
                    "uri": "/customers/f81d98dd-c2f4-499e-a194-5619e260344e/orders/f76c6b7f449d",
                    "method": "GET",
                    "headers": []
                },
                "provisioningStatus": {
                    "uri": "/customers/f81d98dd-c2f4-499e-a194-5619e260344e/orders/f76c6b7f449d/provisioningstatus",
                    "method": "GET",
                    "headers": []
                },
                "patchOperation": {
                    "uri": "/customers/f81d98dd-c2f4-499e-a194-5619e260344e/orders/f76c6b7f449d",
                    "method": "PATCH",
                    "headers": []
                }
            },
            "client": {},
            "attributes": {
                "objectType": "Order"
            }
        }
    ],
    "attributes": {
        "objectType": "CartCheckoutResult"
    }
}

REST 要求

要求語法

方法 要求 URI
PUT {baseURL}/v1/customers/{customer-id}/carts/{cart-id} HTTP/1.1

URI 參數

使用下列路徑參數來識別客戶,並指定要更新的購物車。

名稱 類型​​ 必要 描述
customer-id string Yes 識別客戶的 GUID 格式客戶識別碼。
cart-id string Yes 識別購物車的 GUID 格式化購物車標識碼。

要求標頭

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

要求本文

下表描述 要求本文中的 Cart 屬性。

屬性 型別 必要 描述
id string No 成功建立購物車時提供的購物車標識碼。
creationTimeStamp Datetime No 以日期時間格式建立購物車的日期。 在成功建立購物車時套用。
lastModifiedTimeStamp Datetime No 購物車上次更新的日期,以日期時間格式顯示。 在成功建立購物車時套用。
expirationTimeStamp Datetime No 購物車到期的日期,以日期時間格式顯示。 在成功建立購物車時套用。
lastModifiedUser string No 上次更新購物車的使用者。 在成功建立購物車時套用。
明細項目 物件陣列 Yes CartLineItem 資源的陣列

下表描述 要求本文中的 CartLineItem 屬性。

屬性 型別 必要 描述
id string No 購物車明細專案的唯一標識符。 在成功建立購物車時套用。
catalogId string Yes 目錄項目識別碼。
friendlyName string No 選擇性。 夥伴所定義之專案的易記名稱,以協助釐清。
promotionId string No 選擇性。 大部分 NCE 促銷都會自動套用,不過對於選擇性促銷(例如 Bridge to the Cloud 2)套用至購物車明細專案,合作夥伴必須在新增至購物車要求中包含促銷標識符。
數量 int Yes 授權或實例的數目。
currencyCode string No 貨幣代碼。
billingCycle Object Yes 目前期間所設定的計費周期類型。
參與者 物件字串組的清單 No 購買的參與者集合。
provisioningContext <字典字串,字串> No 用於布建供應項目的內容。
orderGroup string No 表示哪些專案可以放在一起的群組。
error Object No 在錯誤中建立購物車之後套用。
AdditionalPartnerIdsOnRecord String No 當間接提供者代表間接轉銷商下訂單時,僅以其他間接轉銷商的 PartnerID 填入此字段(絕不是間接提供者的標識符)。 獎勵不適用於這些其他轉銷商。 最多只能輸入五個間接轉銷商。 這隻是歐盟/EFTA 國家/地區內交易的適用合作夥伴。

要求範例

PUT /v1/customers/d6bf25b7-e0a8-4f2d-a31b-97b55cfc774d/carts/65faf57b-0205-47ee-92b3-08dcf233ea73/ HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 4fa6dad6-a89f-4875-8247-8294a10ae1cf
MS-CorrelationId: 0e93c70c-977a-4a88-9580-7cf084c73286
X-Locale: en-US
MS-PartnerCenter-Client: Partner Center .NET SDK
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 496
Expect: 100-continue

{
    {
        "Id":"b4c8fdea-cbe4-4d17-9576-13fcacbf9605",
        "CreationTimestamp":"2018-03-15T17:15:02.3840528Z",
        "LastModifiedTimestamp":"2018-03-15T17:15:02.3840528Z",
        "ExpirationTimestamp":"0001-01-01T00:00:00",
        "LastModifiedUser":"2713ccd7-ea3b-470a-9cfb-451d5d0482cc",
        "LineItems":[
            {
                "Id":0,
                "CatalogItemId":"DG7GMGF0DWTL:0001:DG7GMGF0DSJB",
                "FriendlyName":"A_sample_Azure_RI",
                "Quantity":2,
                "BillingCycle":"one_time",
                "ProvisioningContext": {
                    "SubscriptionId": "3D5ECED6-1151-44C7-AEE6-70A4BB725666",
                    "Scope": "shared",
                    "Duration": "1Year"
                }
            }
        ],
    }
}

重要

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

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

REST 回應

如果成功,這個方法會在回應本文中傳回填入 的 Cart 資源。

回應成功和錯誤碼

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

回應範例

HTTP/1.1 201 Created
Content-Length: 764
Content-Type: application/json; charset=utf-8
MS-CorrelationId: 0e93c70c-977a-4a88-9580-7cf084c73286
MS-RequestId: 4fa6dad6-a89f-4875-8247-8294a10ae1cf
X-Locale: en-US,en-US
MS-CV: sF/wRa2ih0CzbABc.0
MS-ServerId: 000001
Date: Thu, 15 Mar 2018 17:15:01 GMT
{
    "id": "b4c8fdea-cbe4-4d17-9576-13fcacbf9605",
    "creationTimestamp": "2018-03-15T17:15:02.3840528Z",
    "lastModifiedTimestamp": "2018-03-15T17:15:02.3840528Z",
    "lastModifiedUser": "2713ccd7-ea3b-470a-9cfb-451d5d0482cc",
    "lineItems": [
        {
            "id": 0,
            "catalogItemId": "DG7GMGF0DWTL:0001:DG7GMGF0DSJB",
            "friendlyName": "A_sample_Azure_RI",
            "quantity": 2,
            "currencyCode": "USD",
            "billingCycle": "one_time",
            "ProvisioningContext": {
                "subscriptionId": "3D5ECED6-1151-44C7-AEE6-70A4BB725666",
                "scope": "shared",
                "duration": "1Year"
            }
            "orderGroup": "0"
        }
    ],
    "links": {
        "self": {
            "uri": "/v1/customers/d6bf25b7-e0a8-4f2d-a31b-97b55cfc774d/carts/b4c8fdea-cbe4-4d17-9576-13fcacbf9605/",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Cart"
    }
}