Add to Cart

Add a product to the cart.

1POST /v2/cpq/carts/{cart_ID}/items

By default, items deleted from a cart are not evaluated for Vlocity Rules. To enable evaluation of deleted items, set the ShouldConsiderDeletedItems configuration setting to true. CME packages are large.

Note

This API supports the guest user enhancements that Salesforce introduced with the Winter ‘21 release. To encrypt and decrypt data for guest users, use the UserSecurity class with this API. See Guest User Technical Details.

For additional information, ​see UserSecurity Class and CPQ and Digital Commerce Changes for Guest Users.

Remote Method 

1postCartsItems

The postCartsItems method supports the addition of one item at a time. If you must add multiple items, make multiple postCartsItems calls.

Note

REST Handler 

1APIItemsCartsCpqV2

Apex Remote Service 

1Class: vlocity_cmt.CardCanvasController
2Method: global static Object doGenericInvoke(String sClassName, String sMethodName, String input, String options)

Apex Remote Input Map 

The following example illustrates how to call this API from Apex code.

1"sClassName": "vlocity_cmt.CpqAppHandler"
2"sMethodName": "postCartsItems"
3"input":  SAME AS SAMPLE REQUEST BODY
4"options": {"vlcClass":"vlocity_cmt.CpqAppHandler"}
1Map<String, Object> inputMap = new Map<String, Object>();
2Map<String, Object> outputMap = new Map<String, Object>();
3Map<String, Object> optionsMap = new Map<String, Object>();
4Map<String, Object> itemsMap = new Map<String, Object>();
5List<Object> items = new List<Object>();
6Id priceBookEntryId = Id.valueOf('Replace with the pricebook entry id of the product to be added');
7Id cartId = Id.valueOf('replace with the id of the cart');
8itemsMap.put('itemId', priceBookEntryId);
9items.add(itemsMap);
10inputMap.put('items', items);
11inputMap.put('cartId', cartId);
12inputMap.put('validate', true); // set to false if validation is not required
13inputMap.put('price', true); // set to false if pricing is not required
14vlocity_cmt.CpqAppHandler cpqAppHandlerService = new  vlocity_cmt.CpqAppHandler();
15cpqAppHandlerService.invokeMethod('postCartsItems', inputMap, outputMap, optionsMap);
16System.debug('outputMap:' + outputMap);

Package 

Communication (vlocity_cmt)

API Parameters and Response Format 

For API parameter names and descriptions, see Cart-Based API Swagger Reference.

Resource Information 

Response FormatJSON
Resource URL/v2/cpq/carts/*/items Example: /services/apexrest/{namespace}/v2/cpq/carts/801360000000oQ9/items

Example Request 

1{
2  "methodName": "postCartsItems",
3  "items": [
4    {
5      "parentId": "8021N000006wtTTQAY",
6      "parentHierarchyPath": "01to000000Am1FGAAZ",
7      "itemId": "01u1N00000DPpdFQAT",
8      "parentRecord": {
9        "records": [
10          {
11            "displaySequence": -1,
12            "Id": {
13              "value": "8021N000006wtTTQAY",
14              "previousValue": null,
15              "originalValue": null,
16              "messages": [],
17              "label": "Order Product ID",
18              "hidden": false,
19              "fieldName": "Id",
20              "editable": false,
21              "dataType": "ID",
22              "actions": {}
23            },
24            "Pricebook2Id": "01so0000000jvwiAAA",
25            "Product2Id": "01to000000Am1FGAAZ",
26            "UnitPrice": {
27              "value": 0,
28              "previousValue": null,
29              "originalValue": null,
30              "messages": [],
31              "label": "Unit Price",
32              "hidden": true,
33              "fieldName": "UnitPrice",
34              "editable": false,
35              "dataType": "CURRENCY",
36              "actions": {}
37            },
38            "Name": "Product Hier 3",
39            "vlocity_cmt__RecurringPrice__c": 0,
40            "IsActive": true,
41            "Product2": {
42              "attributes": {
43                "type": "Product2",
44                "url": "/services/data/v41.0/sobjects/Product2/01to000000Am1FGAAZ"
45              },
46              "Name": "Product Hier 3",
47              "vlocity_cmt__IsConfigurable__c": false,
48              "RecordTypeId": "012o0000000pDXFAA2",
49              "Id": "01to000000Am1FGAAZ",
50              "vlocity_cmt__JSONAttribute__c": null
51            },
52            "productId": "01to000000Am1FGAAZ",
53            "defaultQuantity": 1,
54            "minQuantity": 0,
55            "maxQuantity": 1000,
56            "groupMinQuantity": 0,
57            "groupMaxQuantity": 99999,
58            "sequenceNumber": 1,
59            "productChildItemDefinition": {
60              "attributes": {
61                "type": "vlocity_cmt__ProductChildItem__c",
62                "url": "/services/data/v41.0/sobjects/vlocity_cmt__ProductChildItem__c/a0ro00000050PjxAAE"
63              },
64              "Id": "a0ro00000050PjxAAE",
65              "Name": "Root PCI",
66              "vlocity_cmt__IsVirtualItem__c": false,
67              "vlocity_cmt__Quantity__c": 1,
68              "vlocity_cmt__MaxQuantity__c": 99999,
69              "vlocity_cmt__MinQuantity__c": 0,
70              "vlocity_cmt__MaximumChildItemQuantity__c": 99999,
71              "vlocity_cmt__MinimumChildItemQuantity__c": 0,
72              "vlocity_cmt__IsOverride__c": false,
73              "vlocity_cmt__ParentProductId__c": "01to000000Am1FGAAZ",
74              "vlocity_cmt__ChildLineNumber__c": "1",
75              "vlocity_cmt__SeqNumber__c": 1,
76              "vlocity_cmt__CollapseHierarchy__c": false,
77              "vlocity_cmt__IsRootProductChildItem__c": true,
78              "vlocity_cmt__ParentProductId__r": {
79                "attributes": {
80                  "type": "Product2",
81                  "url": "/services/data/v41.0/sobjects/Product2/01to000000Am1FGAAZ"
82                },
83                "Name": "Product Hier 3",
84                "Id": "01to000000Am1FGAAZ",
85                "RecordTypeId": "012o0000000pDXFAA2"
86              }
87            },
88            "productHierarchyPath": "01to000000Am1FGAAZ",
89            "name": "Product Hier 3",
90            "isVirtualItem": false,
91            "provisioningStatus": "New",
92            "hasChildren": true,
93            "itemType": "lineItem",
94            "PricebookEntryId": {
95              "value": "01uo000000Bz2qbAAB",
96              "previousValue": null,
97              "originalValue": null,
98              "messages": [],
99              "label": "Price Book Entry ID",
100              "hidden": false,
101              "fieldName": "PricebookEntryId",
102              "editable": false,
103              "dataType": "REFERENCE",
104              "actions": {}
105            },
106            "Quantity": {
107              "value": 1,
108              "previousValue": null,
109              "originalValue": null,
110              "messages": [],
111              "label": "Quantity",
112              "hidden": false,
113              "fieldName": "Quantity",
114              "editable": true,
115              "dataType": "DOUBLE",
116              "actions": {}
117            },
118            "vlocity_cmt__OneTimeTotal__c": {
119              "value": 300,
120              "previousValue": null,
121              "originalValue": null,
122              "messages": [],
123              "label": "One Time Total",
124              "hidden": false,
125              "fieldName": "vlocity_cmt__OneTimeTotal__c",
126              "editable": false,
127              "dataType": "CURRENCY",
128[EXAMPLE TRUNCATED FOR BREVITY]

Example Response 

1{
2  "totalSize": 1,
3  "messages": [
4    {
5      "severity": "INFO",
6      "messageId": null,
7      "message": "Successfully added.",
8      "code": "150",
9      "bundleId": null,
10      "actions": {}
11    }
12  ],
13  "actions": {
14    "addtocart": {
15      "rest": {
16        "params": {
17          "cartId": "8011N00000157LkQAI",
18          "items": [
19            {
20              "isPartialPromo": true,
21              "itemId": "a2w1N000001F9TiQAK"
22            }
23          ]
24        },
25        "method": "POST",
26        "link": "/services/apexrest/vlocity_cmt/v2/cpq/carts/8011N00000157LkQAI/promotions"
27      },
28      "remote": {
29        "params": {
30          "items": [
31            {
32              "isPartialPromo": true,
33              "itemId": "a2w1N000001F9TiQAK"
34            }
35          ],
36          "cartId": "8011N00000157LkQAI",
37          "methodName": "postCartsPromoItems"
38        }
39      },
40      "client": {
41        "params": {
42          "methodName": "postCartsPromoItems",
43          "items": [
44            {
45              "isPartialPromo": true,
46              "itemId": "a2w1N000001F9TiQAK"
47            }
48          ]
49        }
50      }
51    },
52    "itempricesupdated": {
53      "rest": {
54        "params": {},
55        "method": "GET",
56        "link": "/services/apexrest/vlocity_cmt/v2/cpq/carts/8011N00000157LkQAI/price"
57      },
58      "remote": {
59        "params": {
60          "cartId": "8011N00000157LkQAI",
61          "methodName": "getCartLineItemPrices"
62        }
63      },
64      "client": {
65        "params": {}
66      }
67    }
68  },
69  "records": [
70    {
71      "messages": [],
72      "displaySequence": -1,
73      "vlocity_cmt__InCartQuantityMap__c": {
74        "value": {
75          "01t1N00000AptOXQAZ": 1,
76          "01t1N00000AptOcQAJ": 1,
77          "01t1N00000ApqNdQAJ": 1,
78          "01t1N00000ByiiDQAR": 1
79        },
80        "previousValue": null,
81        "originalValue": null,
82        "messages": [],
83        "label": "InCartQuantityMap",
84        "hidden": true,
85        "fieldName": "vlocity_cmt__InCartQuantityMap__c",
86        "editable": false,
87        "dataType": "TEXTAREA",
88        "actions": {}
89      },
90      "Id": {
91        "value": "8021N000006wtTTQAY",
92        "previousValue": null,
93        "originalValue": null,
94        "messages": [],
95        "label": "Order Product ID",
96        "hidden": false,
97        "fieldName": "Id",
98        "editable": false,
99        "dataType": "ID",
100        "actions": {}
101      },
102      "isVirtualItem": false,
103      "lineItems": {
104        "totalSize": 0,
105        "messages": [],
106        "records": [
107          {
108            "messages": [],
109            "actions": {
110              "addtocart": {
111                "rest": {
112                  "params": {
113                    "items": [
114                      {
115                        "quantity": 1,
116                        "parentId": "8021N000006wtTTQAY",
117                        "parentHierarchyPath": "01to000000Am1FGAAZ",
118                        "itemId": "01u1N00000DPpdFQAT"
119                      }
120                    ],
121                    "cartId": "8011N00000157LkQAI",
122                    "price": true,
123                    "validate": true,
124                    "includeAttachment": false,
125                    "pagesize": 10,
126                    "lastRecordId": null,
127                    "query": null
128                  },
129                  "method": "POST",
130                  "link": "/services/apexrest/vlocity_cmt/v2/cpq/carts/8011N00000157LkQAI/items"
131                },
132                "remote": {
133                  "params": {
134                    "methodName": "postCartsItems",
135                    "items": [
136                      {
137                        "quantity": 1,
138                        "parentId": "8021N000006wtTTQAY",
139                        "parentHierarchyPath": "01to000000Am1FGAAZ",
140                        "itemId": "01u1N00000DPpdFQAT"
141                      }
142                    ],
143                    "cartId": "8011N00000157LkQAI",
144                    "price": true,
145                    "validate": true,
146                    "includeAttachment": false,
147                    "pagesize": 10,
148                    "lastRecordId": null,
149                    "query": null
150                  }
151                },
152                "client": {
153                  "params": {}
154                }
155              },
156              "updateitems": {
157                "rest": {
158                  "params": {
159                    "items": [
160                      {
161                        "itemId": "8021N000006wtUMQAY"
162                      }
163                    ],
164                    "filters": null,
165                    "fields": null,
166                    "cartId": "8011N00000157LkQAI",
167                    "price": true,
168                    "validate": true,
169                    "includeAttachment": false,
170                    "pagesize": 10,
171                    "lastRecordId": null,
172                    "query": null
173                  },
174                  "method": "PUT",
175                  "link": "/services/apexrest/vlocity_cmt/v2/cpq/carts/8011N00000157LkQAI/items"
176                },
177                "remote": {
178                  "params": {
179                    "methodName": "putCartsItems",
180                    "items": [
181                      {
182                        "itemId": "8021N000006wtUMQAY"
183                      }
184                    ],
185                    "filters": null,
186                    "fields": null,
187                    "cartId": "8011N00000157LkQAI",
188                    "price": true,
189                    "validate": true,
190                    "includeAttachment": false,
191                    "pagesize": 10,
192                    "lastRecordId": null,
193                    "query": null
194                  }
195                },
196                "client": {
197                  "params": {}
198                }
199              },
200[EXAMPLE TRUNCATED FOR BREVITY]