---
schema_version: "1"
id: 67d68cb10edddc7ea04718bba572de463031047ac0446ec3aa9de171d969f230
title: Update Basket Contents API
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/industries/cme/guides/comms-t-update-basket-contents-api.md
canonical_url: https://developer.salesforce.com/docs/industries/cme/guide/comms-t-update-basket-contents-api.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d45fc2045eadb198fa951e968b7c2e877f3ed25b83b68e5ebb4086b077865d8e
products:
  - Communications, Media, Energy and Utilities APIs (Managed Package)
  - Industries Developer Documentation
---
# Update Basket Contents API

The Basket API provides the ability to add, delete, and modify the contents of a basket. You can add or delete offers, and update the quantity or attributes of an offer that was previously added to a basket. The API works for both known and anonymous users.

You can update the quantity and attributes for root items, child items of parent items, and child items of virtual groups. Some definitions that might be helpful:

- lineItemKey: A unique key generated for a line item

- Quantity: The number of items. Includes any root or child item.

- bundleContextKey: A unique key generated for a bundle

- cartContextKey: The key for the cart

You use the cartContextKey to keep track of the basket. The cartContextKey is not required if the basket is empty. The cartContextKey is returned as part of the response after a successful basket operation.

Offers may include both products and promotions and use unique offer codes, thereby removing dependency on Salesforce IDs. Offers can be added directly or after configuration.

The API returns the entire bundle structure that is contained in the basket. The list structure complies with pricing, overrides, rules, adjustments, attributes, and so on.

The API uses cartContext to track existing basket contents and appropriate context parameters to price/run rules.

To improve performance, the API returns the contents of the cache if possible. If the data is not cached, the API call is treated as a cache-miss and handled (also resulting in a corresponding cache entry).

The API also permits the user to delete items from an existing basket with the deleteBundleNumber parameter.

The API can be used in any of three ways, depending on the value of the basketAction parameter. The allowable options for basketAction are addWithNoConfig, addAfterConfig, and deleteFromBasket.

If you know the offer code, specify it using the offer parameter, as shown below:

```nolang
{
  "offer":"NS_DC_ROOT-1",
  "basketAction":"AddWithNoConfig"
}
```

When deleting a bundle from a basket, specify the bundle number in the deleteBundleNumber parameter.

The Fall '20 release includes an Attribute Basket Cache feature. See [Attribute Basket Cache Exclusion](/docs/commerce/commerce/guide/comms-t-attribute-basket-cache-exclusion.html).


## Rules Supported

- [Context Eligibility Rules for Products and Promotions](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-context-eligibility-rules.md)

- Response contains base prices only (see [Product Pricing in EPC](https://help.salesforce.com/s/articleView?id=ind.comms_product_pricing_in_epc.htm))

- [Pricing context eligibility rules](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-context-eligibility-rules.md) for known users are supported.

- Pricing Interface (see [Attribute-Based Pricing](https://help.salesforce.com/s/articleView?id=ind.comms_attribute_based_pricing.htm))

- Product Validation Interface (see [Context Rules Framework](https://help.salesforce.com/s/articleView?id=ind.comms_context_rules_framework.htm) and [Advanced Rules Framework](https://help.salesforce.com/s/articleView?id=ind.comms_advanced_rules_framework.htm))

- For anonymous users, [Advanced Rules](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-advanced-rules.md) are supported for [Defining Advanced Rules Using Configuration Type](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-defining-advanced-rules-using-configuration-type.md) and [Defining Advanced Rules Using Attribute Configuration Type](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-defining-advanced-rules-using-attribute-configuration-type.md) only.

- For known users, [Advanced Rules](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-advanced-rules.md) are supported for [Defining Advanced Rules Using Configuration Type](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-defining-advanced-rules-using-configuration-type.md) and [Defining Advanced Rules Using Attribute Configuration Type](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-defining-advanced-rules-using-attribute-configuration-type.md) only.

- [Product Relationships](https://help.salesforce.com/s/articleView?id=ind.comms_product_relationships_overview.htm) are supported with filters, for example, product A removes Product B.

- [Pricing](https://help.salesforce.com/s/articleView?id=ind.comms_pricing_definition.htm) is supported. However, for pricing, do not use Pricing for Advance Rules. Always use the Custom Pricing Plan, which triggers [Attribute-Based Pricing](https://help.salesforce.com/s/articleView?id=ind.comms_attribute_based_pricing.htm).

- [Using Context Rules with Digital Commerce APIs](https://help.salesforce.com/s/articleView?id=ind.comms_using_context_rules_with_digital_commerce_apis.htm)

## Prerequisites

- Products must have ProductCode populated (no spaces are allowed in ProductCode).

- Promotions must have Code**c populated (no spaces are allowed in Code**c).

- A catalog must be present with products and promotions attached to it as records under the CatalogProductRelationship**c object. The catalog should have CatalogCode**c populated (no spaces are allowed in CatalogCode\_\_c).

- The catalog must be attached to a default price list through the DefaultPriceList**c field on the Catalog**c object.

- Price list entries must exist for all the products that are attached to the catalog.

- Optional: To populate the cache, the following batch jobs may be run:

  - Context combinations

  - Offer details

  - Pricing results

- Create a custom setting called [CacheAPIFields](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference_148927.htm) with a value of true. CacheAPIFields is not required for CME 103.1.14 and later versions.


## Parameters

For API parameter names and descriptions, see [Digital Commerce REST API](https://developer.salesforce.com/docs/industries/cme/references/dc-rest1?meta=Summary).

## Response

For detailed API response descriptions, see [Digital Commerce REST API](https://developer.salesforce.com/docs/industries/cme/references/dc-rest1?meta=Summary)

## Modify Basket for an Anonymous User

For example, when the basket is empty, to add an item to the basket without configuring:

```nolang
POST /v3/catalogs/{catalog_code}/basket/{basket_key}
```

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket

Request body:
{"offer":"{offer_code}","basketAction":"AddWithNoConfig"}
```

To add an item to the basket after configuring (by running the previous example and changing the quantity to 2) with basket after previous API call. The productConfig parameter accepts stringified offer details in this example.

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket/50ba987c870c64774e24c27787288650

Request body:
{"offer":"{offer_code}","basketAction":"AddWithNoConfig"}
```

To add after configuring (in this case, changing the quantity to 2) with basket after previous API call. The productConfig parameter accepts offer details directly (as a map) in this example.

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket/50ba987c870c64774e24c27787288650
```

**note:** The list grows from the bottom; that is if you add products A, B, and C in that order, the JSONResult.records list would be C,B,A with respective numbering as 0, 1, and 2. Therefore, list item 0 will always be the most recent addition.

To delete bundle 1 from the basket (assuming the previous API calls were run):

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket/2c2be114be30ac296d219f95d3c984d5
```

## Context Parameters

Context parameters can be passed to the API, as in the following examples:

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket?context={"Status":"Active"}
```

```nolang
POST
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket?context={"SLA__c":"Silver","Status":"Inactive"}
```

## Modify Basket for a Known User

You can add context information if the user is known to the system.

```nolang
POST /v3/catalogs/{catalog_code}/basket/{basket_key}context={"accountId":"account_ID"}&isloggedin=true
```

This API supports the isloggedin flag to indicate whether a user is logged in or anonymous. If the isloggedin flag is true, it indicates a logged-in user, and an accountId must be specified in the context parameter of the API call. If the isloggedin flag is false, it indicates that the user is anonymous.

In the returned JSON, the bundleContextKey uniquely identifies a bundle within the basket. Use this key when you need to identify a particular bundle. The lineItemKey parameter uniquely identifies a line item.

Also in the returned JSON, the actions node displays API calls for updating and deleting items.

The following are some examples for logged-in users.

Add a Product to an Empty Basket:

```nolang
POST
/services/apexrest/{namespace}/catalogs/{catalog_code}/basket?context={"accountId":"account_ID"}&isloggedin=true

Request body:
{"offer":"offer_ID",
"basketAction":"AddWithNoConfig"}

```

Note that in the following example the basket key is specified in the API:

```nolang
POST
/services/apexrest/{namespace}/catalogs/{catalog_code}/basket/{basket_key}?context={"accountId":"account_ID"}&isloggedin=true

Request body:
{"offer":"offer_ID",
"basketAction":"AddWithNoConfig"}
```

Add a Child Product to a Basket:

```nolang
POST
/services/apexrest/{namespace}/catalogs/{catalog_code}/basket/{basket_key}?context={"accountId":"account_ID"}&isloggedin=true

Request body:
{
  "parentLineItemKey":"parent line item key",
  "parentHierarchyPath":"parent hierarchy path,
  "offer":"Family",
  "basketAction":"addWithNoConfig",
  "bundleContextKey":"bundle context key"
}
```

Remove a Product or Child Product from a Basket:

```nolang
POST
/services/apexrest/{namespace}/catalogs/{catalog_code}/basket/{basket_key}?context={"accountId":"account_ID"}&isloggedin=true

Request body:
{
  "basketAction":"deleteFromBasket",
  "lineItemKey":"line_item_key",
  "bundleContextKey":"bundle_context_key"
}
```

Remove a Child Product from a Basket:

```nolang
POST
/services/apexrest/{namespace}/catalogs/{catalog_code}/basket/{basket_key}?context={"accountId":"account_ID"}&isloggedin=true

Request body:
{
  "basketAction":"deleteFromBasket",
  "lineItemKey":"line_item_key",
  "bundleContextKey":"bundle_context_key"
}
```

If the API call violates cardinality rules (such as attempting to add or remove more than the maximum or minimum quantity) a message is returned in the messages node (although the API returns no error or error code).

## Update Basket Items for an Anonymous User

To update the quantity of an item:

```nolang
Method: PUT

API:
/services/apexrest/{namespace}/v3/catalogs/{catalog}/basket/{cart_context_key}

Request Body:
{
 "lineItemKey":"xxxxxxxxxxxx",
 "Quantity":"2"
 "bundleContextKey":"xxxxxxxxxxxxx"
}
```

To update the quantity of an item:

```nolang
Method: PUT

API:
/services/apexrest/{namespace}/v3/catalogs/{catalog_code}/basket/{cart_context_key}?context={"accountId":"account_ID"&isloggedin=true

Request Body:
{
 "bundleContextKey":"bundle_context_key",
 "lineItemKey":"line_item_key",
 "Quantity":"2",
 "basketAction":"updatebasket"
}
```

To update item attributes:

```nolang
Method: PUT

API:
/services/apexrest/{namespace}/v3/catalogs/{catalog_code}/basket/{cart_context_key}?context={"accountId":"account_ID"&isloggedin=true

Request Body:
{
  "lineItemKey": "043f392362aaa1164871f3d5fb78b651",
  "bundleContextKey": "043f392362aaa1164871f3d5fb78b651",
  "Quantity": "4",
  "attributeCategories": {
    "totalSize": 1,
    "records": [
      {
        "displaySequence": -123,
        "Code__c": "NS-COLORS",
        "Name": "NS-COLORS",
        "id": "a080b00000kds8yAAA",
        "productAttributes": {
          "totalSize": 3,
          "records": [
            {
              "code": "COLOR-1",
              "dataType": "text",
              "inputType": "checkbox",
              "multiselect": false,
              "required": false,
              "readonly": false,
              "disabled": false,
              "filterable": true,
              "attributeId": "a090b00000W1zWPAAZ",
              "label": "Color1",
              "displaySequence": 1,
              "hasRules": false,
              "hidden": false,
              "cloneable": true,
              "isNotTranslatable": false,
              "values": [
                {
                  "readonly": false,
                  "disabled": false,
                  "value": true,
                  "defaultValue": true,
                  "selected": true,
                  "defaultSelected": true
                }
              ],
              "userValues": false
            },
            {
              "code": "COLOR-2",
              "dataType": "text",
              "inputType": "text",
              "multiselect": false,
              "required": false,
              "readonly": false,
              "disabled": false,
              "filterable": true,
              "attributeId": "a090b00000W1zWUAAZ",
              "label": "Color2",
              "displaySequence": 2,
              "hasRules": false,
              "hidden": false,
              "cloneable": true,
              "isNotTranslatable": false,
              "values": [
                {
                  "readonly": false,
                  "disabled": false,
                  "value": "Color2",
                  "defaultValue": "Color2"
                }
              ],
              "userValues": "Color22"
            },
            {
              "code": "COLOR-3",
              "dataType": "number",
              "inputType": "number",
              "multiselect": false,
              "required": true,
              "readonly": false,
              "disabled": false,
              "filterable": true,
              "attributeId": "a090b00000W1zWZAAZ",
              "label": "Color3",
              "displaySequence": 3,
              "hasRules": false,
              "hidden": false,
              "cloneable": true,
              "isNotTranslatable": false,
              "values": [
                {
                  "readonly": false,
                  "disabled": false,
                  "value": 12,
                  "defaultValue": 12
                }
              ],
              "userValues": 1221
            }
          ]
        }
      }
    ]
  }
}
```
