---
schema_version: "1"
id: d5690571e6892cee281919025e42040ed8387b2644157653de22e6a683fee0fe
title: Basket Validation
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/industries/cme/guides/comms-t-basket-validation.md
canonical_url: https://developer.salesforce.com/docs/industries/cme/guide/comms-t-basket-validation.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a294df939f5e0ea0495691746e7bb09b21897513785bbaf6dbd94a3c978ea7b4
products:
  - Communications, Media, Energy and Utilities APIs (Managed Package)
  - Industries Developer Documentation
---
# Basket Validation

Basket validation ensures that certain conditions are met before performing an operation on a basket.

The following basket items are checked:

- The user is eligible for the offers contained in the basket.

- The offers in the basket are effective.

- The price list entries that were used to create the basket are still effective.

Basket validation is enabled or disabled by passing the validatebasket query parameter. The default value is true. To turn off the basket validation, pass false as the value for the query parameter.

The basket operations that supports basket validation are shown here:

| Basket Operation                     | Description                                                                                                                             |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| Add offer to a basket                | The effectivity and eligibility of the bundle offer is checked. If the offer is eligible and effective, the add-to-basket will proceed. |
| Add new offer to an existing basket  | The existing basket is validated. Only when the basket is valid, any add or update operations are allowed.                              |
| Update an existing basket            | The existing basket is validated. Only when the basket is valid, any add or update operations are allowed.                              |
| Get basket details                   | The basket details are validated. Depending on the validation result, the response will be modified.                                    |
| Delete offer from an existing basket | The delete operation is performed first, and the validation is preformed on the remaining offers in the basket.                         |
| Create cart using a basket           | The basket is validated. Only if the validation is successful will cart creation be allowed.                                            |

The fields in the table below are checked when performing effectivity checking:

| Attributes             | Fields                                                                                                      |
| ---------------------- | ----------------------------------------------------------------------------------------------------------- |
| For products           | IsActive, IsOrderable, SellingStartDate, SellingEndDate, EndOfLifeDate                                      |
| For promotions         | IsActive, IsOrderable, EffectiveFrom, EffectiveUntil                                                        |
| For price list entries | IsActive, EffectiveFrom, EffectiveUntil, CalculatedEffectiveDate (based on applied TimePlan and TimePolicy) |

**important:** Adding assets to the basket after the SellingEndDate is not supported due to implementation limitations.

## Example 1: Validation when adding a new offer to a basket

When adding an offer (either a product or promotion) to the basket (either an empty basket or an existing valid basket), the eligibility and effectivity of the offer that is being added is checked. Only when the offer is eligible and effective will the basket be created. For invalid offers, depending on the reason, the different responses are shown below.

Example: An ineligible offer is added for anonymous users.

```nolang
Request URL
/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket

Request Body
{"offer":"DTHOffer","basketAction":"AddWithNoConfig"}

Condition
The product, DTHOffer, has a rule applied. The rule is valid for Account SLA=Silver. The default value for rule dimension is Bronze.

Response
{"success":false,"result":{"BasketValidationResult":{"IneligibleOffers":["DTHOffer"]}},"errorCode":"422","error":"One or more offers are ineligible."}
```

Response:

![validation1](https://developer.salesforce.com/docs/media/validation_1.png)

Example: An ineligible offer is added for logged-in users.

```nolang
Request URL
/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket?context={"accountId":"<<AccountId With SLA not as Silver>>"}&isloggedin=true

Request Body
{"offer":"DTHOffer","basketAction":"AddWithNoConfig"}

Condition
The product, DTHOffer, has a rule applied. The is valid for Account SLA = Silver. The default value for rule dimension is Bronze

Response
{"success":false,"result":{"BasketValidationResult":{"IneligibleOffers":{"DTHOffer":"The SLA of Account should be SILVER"}}},"errorCode":"422","error":"One or more offers are ineligible."}
```

Response:

![Validation2](https://developer.salesforce.com/docs/media/validation_2.png)

Example: The offer being added is not effective.

```nolang
Request URL
/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket

Request Body
{"offer":"SportsPack","basketAction":"AddWithNoConfig"}

Condition
The SellingEndDate of the offer SportsPack has expired

Response
{"success":false,"result":{"BasketValidationResult":{"InvalidOffers":{"SportsPack":["SellingEndDate"]}}},"errorCode":"422","error":"The offer being added to the basket is ineffective"}
```

Response

![Validation3](https://developer.salesforce.com/docs/media/validation_3.png)

Example: The product being added to the basket does not have a valid price list entry.

```nolang
Request URL
/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket

Request Body
{"offer":"EntertainmentPack","basketAction":"AddWithNoConfig"}

Condition
There are no valid PLEs on the offer EntertainmentPack 

Response
{"success":false,"errorCode":"INVOKE-500","error":"No valid price list entry found for product EntertainmentPack"}
```

Response:

![Validation4](https://developer.salesforce.com/docs/media/validation_4.png)

## Example 2: Validation while running a basket operation on an invalid basket

An existing basket might have one or more ineligible offers in it. This may be because the basket was created in an older version of the product (pre-Fall '20) or the basket was created with validatebasket query parameter set to false. For this example, assume that the basket was created with a bundle named DTHOffer, and DTHOffer is eligible only if the account SLA is Silver. Also, the default value of the SLA is Bronze. Below is the basket structure:

Example: Validation while performing basket operation on an invalid basket having ineligible offer(s)

```nolang
{
  "totalSize": 1,
  "records": [
    {
      "displaySequence": -1,
      "Id": {
        "value": "8026g000003qmNjAAI",
        "previousValue": null,
        "originalValue": null,
        "messages": [],
        "label": "Order Product ID",
        "hidden": false,
        "fieldName": "Id",
        "editable": false,
        "dataType": "ID",
        "alternateValues": null,
        "actions": {}
      },
      "Pricebook2Id": "01s6g000008qDnSAAU",
      "Product2Id": "01t6g000003yHyWAAU",
      "ProductCode": "DTHOffer",
      "UnitPrice": {
        "value": 0,
        "previousValue": null,
        "originalValue": null,
        "messages": [],
        "label": "Unit Price",
        "hidden": true,
        "fieldName": "UnitPrice",
        "editable": false,
        "dataType": "CURRENCY",
        "alternateValues": null,
        "actions": {}
      },
      "Name": "DTHOffer",
      "IsActive": true,
      "dc_108__RecurringPrice__c": 25,
      "Product2": {
        "attributes": {
          "type": "Product2",
          "url": "/services/data/v49.0/sobjects/Product2/01t6g000003yHyWAAU"
        },
        "Id": "01t6g000003yHyWAAU",
        "Name": "DTHOffer",
        "dc_108__IsConfigurable__c": false,
        "dc_108__GlobalGroupKey__c": "eeed75c1-d269-c274-796d-0babcbf4d6fb",
        "dc_108__Type__c": "None",
        "dc_108__SubType__c": "None",
        "RecordTypeId": "0126g000001MCLdAAO",
        "dc_108__JSONAttribute__c": null
      },
      "CurrencyCode": "USD",
      "productId": "01t6g000003yHyWAAU",
      "defaultQuantity": 1,
      "minQuantity": 0,
      "maxQuantity": 99999,
      "groupMinQuantity": 0,
      "groupMaxQuantity": 99999,
      "sequenceNumber": 1,
      "productChildItemDefinition": {
        "attributes": {
          "type": "dc_108__ProductChildItem__c"
        },
*** and so on ***
```

For the above basket, a subsequent basket operation will return one of the following responses:

- Anonymous user:

  ```nolang
  Operation
  Add Promotion to existing Basket

  Condition
  The basket was created by an anonymous user and the next basket operation is also being performed by an anonymous user.

  Request URL/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket/273ea5445b7b80ab40b566baab089e41

  Request Body
  {"basketAction":"AddWithNoConfig","offer":"10%OffDTH"}

  Response
  {
    "success": false,
    "cartContextKey": "273ea5445b7b80ab40b566baab089e41",
    "result": {
      "BasketValidationResult": {
        "isBasketValid": false,
        "basketValidationMessage": "One or more offers are ineligible.",
        "IneligibleOffers": [
          "DTHOffer"
        ]
      },
      "totals": {
        "EffectiveOneTimeTotal__c": 200,
        "EffectiveRecurringTotal__c": 25
      },
      "records": [
        {
          "actions": {
            "deleteFromBasketAction": {
              "rest": {
                "params": {
                  "basketAction": "deleteFromBasket",
                  "lineItemKey": "eb4ba8910c60a25ae4d4dda7a1b60c64",
                  "bundleContextKey": "eb4ba8910c60a25ae4d4dda7a1b60c64"
                },
                "link": "/v3/catalogs/DTHCatalog/basket/273ea5445b7b80ab40b566baab089e41?contextKey=9d6af941cb9c06b0a31d0e6be2dddf17",
                "method": "deleteFromBasketAction"
              }
            },
            "updateBasketAction": {
              "rest": {
                "params": {
                  "basketAction": "updateBasket",
                  "lineItemKey": "eb4ba8910c60a25ae4d4dda7a1b60c64",
                  "bundleContextKey": "eb4ba8910c60a25ae4d4dda7a1b60c64"
                },
                "link": "/v3/catalogs/DTHCatalog/basket/273ea5445b7b80ab40b566baab089e41?contextKey=9d6af941cb9c06b0a31d0e6be2dddf17",
                "method": "updateBasketAction"
              }
            }
          },
  (truncated for brevity)

  ```

  Result:

  ![Validation5](https://developer.salesforce.com/docs/media/validation_5.png)

- Logged-in user, case 1:

  ```nolang
  Operation
  Add Promotion to existing Basket

  Condition
  The basket was created by a logged in user with account id <<AccountId1>> having SLA as Bronze and the next basket operation is also being performed by the same user without any change to the account shape.

  Request URL/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket/f4f58e16f583e8843ab5cc7c101b864e?context={"accountId":"AccountId1"}&isloggedin=true

  Request Body
  {"basketAction":"AddWithNoConfig","offer":"10%OffDTH"}
  ```

  Result:

  ![Validation6](https://developer.salesforce.com/docs/media/validation_6.png)

- Logged-in user, case 2

  ```nolang
  Operation
  Add Promotion to existing Basket

  Conditions - the response will be similar for both the cases mentioned below

  Condition 1 - The basket was created by logged in user with account id <<AccountId1>> having SLA as Bronze and the next basket operation is being performed by same user but the account SLA has changed to Silver
  Condition 2 - The basket was created by logged in user with account id <<AccountId1>> having SLA as Bronze and the next basket operation is being performed by different user with account id <<AccountId2>> with account SLA Silver

  Request URL/services/apexrest/dc_108/v3/catalogs/DTHCatalog/basket/f4f58e16f583e8843ab5cc7c101b864e?context={"accountId":"AccountId2"}&isloggedin=true

  Request Parameter
  {"basketAction":"AddWithNoConfig","offer":"10%OffDTH"}
  ```

  Result:

  ![Validation7](https://developer.salesforce.com/docs/media/validation_7.png)

## Validation while performing a basket operation on an invalid basket having eligible but ineffective offer(s)

After some time interval, the offers in the basket are eligible but,For offer SportsPack,

- The SellingEndDate and EndOfLifeDate are ineffective.

- The Effective Until Date of the OT PLE,50\$OTCharge, used, is now ineffective

Once the basket is ineffective, further basket operations (except getBasket) return a response similar to the response shown below.

Response

![](https://developer.salesforce.com/docs/media/validation_8.png)

## Understanding the response structure

When an invalid basket is found during basket validation, the response will contain an extra node named BasketValidationResult. In the node, the details about why the basket is invalid are available. The InvalidOffers node contains:

- InvalidPLEs - This node contains the details of all the ineffective price list entries for all of the invalid offers in the basket.

- InvalidProducts - This node contains the details of the products that are invalid, with the name of the fields indicating which product is invalid.

- InvalidPromotions - This node contains the details of the promotion(s) that are invalid, with the name of the fields indicating which the promotion is invalid.

If basket validation fails, the errorCode in the response will be 422 with an appropriate error message.

When a getBasket operation is performed, an extra nextAction node is available in the response. This node contains details about how to correct the basket. See the examples for more information.

## Basket validation limitations

- For add-to-basket operations, validation is performed only when basketAction is set to AddWithNoConfig.

- Price list entry validation is only for price list entries that were used to create the basket. If an offer has more than one price list entry but was not used, then the validation will not be performed for those price list entries.

- Price list entry validation is performed only if the basket was created with active PricingInterface implementation as PricingPlanService.

- Basket validation does not support the price list entry validation if the pricing is done using a custom implementation for PricingInterface; for example, if the prices were picked from a Matrix.

- For price list entry validation, there must be an entry in the CachedAPIResponse\_\_c SObject of Type=pleOfferMap and cacheKey=\<\<CartContextKey>> must be available. If the basket was created using a version earlier than Fall '20, the pleOfferMap will not be available for that basket; therefore the PLE validation for that basket will be skipped.

- Basket validation does not apply to the effectivity of the CatalogProductRelationship.

- When adding a new offer to either an empty or existing basket, validation is performed only for the root offer; that is, only for the offer passed in the post body of the API call. Validations are not done for child products or auto-add relationship products.

- Effectivity checking for new offers is supported starting in Fall '20f. If offer details were generated in an earlier version, the effectivity check for the offer being added to the basket will not occur.

- The eligibility check for the offers in the basket is done only for the offers present in the catalog passed in the input. If there are offers from different catalogs, they will not be checked for eligibility.
