---
schema_version: "1"
id: 0cf418bb68693bca6158ef3010c3df7830f7487d885ce6404f7bc53b62788600
title: Create Basket with BasketAction
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/industries/cme/guides/comms-t-create-basket-with-basketaction.md
canonical_url: https://developer.salesforce.com/docs/industries/cme/guide/comms-t-create-basket-with-basketaction.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: dcf33776ac629d820a068ab4bc1f45db8522430e58c3818e16485808b126fb2a
products:
  - Communications, Media, Energy and Utilities APIs (Managed Package)
  - Industries Developer Documentation
---
# Create Basket with BasketAction

The Create Basket with BasketAction API provides the ability to create a basket from items that were added by a user during the configure operation. Also see [Post Offer Details with Configuration API](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-post-offer-details-with-configuration-api.md).

Use this API to create a basket in the following ways depending on the format of the request body: AddWithNoConfig, AddAfterConfig, and AssetToBasket.

- returnBasket - This flag indicates whether to return basket information in the AssetToBasket API response. The default value is true, meaning that the AssetToBasket API returns basket information as it did in previous releases, ensuring backward compatibility. If set to false, the Assettobasket API returns only the basket key, and not the complete basket. To use the returnBasket flag, the CacheAPI.SkinnyBasket custom setting must be set to true.

- includeAttachments - Use this flag to determine whether the API returns attachments URI or not. The default value is false. If includeAttachment is true, the basket API returns a URI to the attachments. If includeAttachment is false or the isloggedin flag is false, the basket API does not return the attachments.

- When basket items are created, added, modified, or deleted, the basket contents effectivity are validated.

Starting in CME Spring '22, you can update the usage quantity in Basket Operation:

- Pass the usage quantity as “FieldsTobeUpdated“ for the Usage Quantity field.

- Pass the Attribute Binding using the respective attribute in the JSON request.

## AddWithNoConfig

To add the offer without any configured attribute values, pass the following in the request body of the API call:

```nolang
"basketAction":"AddWithNoConfig",
"offer":"offer_code"
```

## AddAfterConfig

To add a configured offer, pass the following in the body of the API call:

```nolang
"basketAction":"AddAfterConfig"
"productConfig":"result_from_Get_Offer_Details_API"
```

## AssetToBasket

To change an asset to a basket, format the body of the API call similar to the following:

```nolang
"basketAction":"AssetToBasket"
"rootAssetIds":"the root asset Ids"
"requestDateTime":"requested_date_time"
```

Use UTC date format for the date-time string: YYYY-MM-DDTHH:MM:SS.SSSZ. Ensure that you specify the requestDateTime parameter using UTC date and time. requestDateTime should be a future date compared to the current local date. A validation check runs to see if requestDateTime is in the future. If not, then it means the date has passed and an error is generated.

**Attribute Basket Cache Exclusion**

The Fall '20 release includes an Attribute Basket Cache feature. See [Attribute Basket Cache Exclusion](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-attribute-basket-cache-exclusion.md).

## Rules Supported

- [Context Eligibility Rules](https://developer.salesforce.com/docs/industries/cme/guide/comms-t-context-eligibility-rules.md) for how 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) types 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) types 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).

- Also see [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

- Catalog should have CatalogCode**c populated; spaces are not allowed in CatalogCode**c.

- Products should have ProductCode populated; spaces are not allowed in ProductCode.

- Promotions should have Code**c populated; spaces are not allowed in Code**c.

- Catalog should be present with products and promotions attached to it as records under the CatalogProductRelationship\_\_c object.

- The Catalog should be attached to a default price list through the DefaultPriceList**c field on Catalog**c object.

- Price list entries should exist for all the products attached to the catalog.

- 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.

- Batch jobs for the following should have been run ahead of time, thereby populating the cache:

  - Context combinations

  - Offer details

  - Pricing results

**note:** Digital Commerce API operations create pseudo accounts or orders in the background for basic computations related to respective API calls.

The pseudo accounts or orders is auto deleted based on the CreateCart interface implementation:

- **DefaultCreateCartImplementation:**During Basket API operations, any pseudo account or order deletion is honored by the custom setting **CacheAPI.DeletePseudoRecords**.

- **CreateCartFromPoolImplementation:**During Basket API operations, any pseudo account or order deletion is not honored by the custom setting **CacheAPI.DeletePseudoRecords**.

## Parameters and Response

For API parameter names and descriptions, see [Digital Commerce REST API](https://developer.salesforce.com/docs/industries/cme/references/dc-rest1?meta=Summary)

## Create Basket API for an Anonymous User

Example: Create a new basket and add an offer.

```nolang
POST /v3/catalogs/{catalog_code}/basket
```

```nolang
Method: POST

API:
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket

Request Body:
{"offer":"iPhone8","basketAction":"AddWithNoConfig"}
```

Example: Add an offer to a previously created basket. In the example, the request body is truncated for clarity.

```nolang
Method: POST

API:
/services/apexrest/vlocity_cmt/v3/catalogs/Mobiles/basket/50ba987c870c64774e24c27787288650

Request Body:
{"basketAction":"AddAfterConfig","productConfig":"{\"offerDetails\":{\"Offer\":{\"priceResult\":...}

```

## Create Basket API for a Known User

Example: Add a Product to an Empty Basket.

```nolang
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket?context={"accountId":"{account_ID}"}&inloggedin=true
```

```nolang
Method: POST

API:
/services/apexrest/vlocity_cmt/catalogs/{catalog_code}/basket?context={"accountId":"{account_ID}"&isloggedin=true

Request Body:
{"offer":"offer_code","basketAction":"AddWithNoConfig"}
```

Example: Add a Product to an Existing Basket.

```nolang
Method: POST

API:
/services/apexrest/vlocity_cmt/catalogs/{catalog_code}/basket/{cart_context_key}?context={"accountId":"{account_ID}"&isloggedin=true

Request Body:
{"offer":"offer_code","basketAction":"AddWithNoConfig"}
```

Example: Create Basket with AddAfterConfig. The payload for AddAfterConfig is a response of GetOfferDetails API inside 'productConfigNode'. If you have the response of offer details, you can add it for AddAfterConfig as follows:

```nolang
{
    "basketAction":"AddAfterConfig",
    "productConfig":
	"offerDetails":<GetOfferDetails response here>
}
```

Example: Convert Asset to Basket. The following example shows how to convert an asset to a basket. The example assumes you know the asset ID you wish to convert to a basket, and also the account of the user.

Format the request as follows:

```nolang
Method: POST

API:
/services/apexrest/vlocity_cmt/v3/catalogs/{catalog_code}/basket?context={accountId":"{account_ID}"&isloggedin=true

Request POST Body:
{"rootAssetIds":"xxxxxxxxxxxxxx",
"basketAction":"AssetToBasket",
"RequestDateTime":"2019-12-22T00:00:00.000Z"}
```

To convert more than one asset, you can specify more than one root asset ID in the body of the API call. Separate asset IDs with a comma:

```nolang
{"rootAssetIds":"asset_1","asset_2","asset_3"
"basketAction":"AssetToBasket",
"RequestDateTime":"2019-12-22T00:00:00.000Z"}
```

Be sure to note the cartContextKey, the lineItemKey, and the bundleContextKey if you intend to change or configure the offer.
