---
schema_version: "1"
id: fb624a87c2c9f9e8fafef9329f16419812dba3ac06d840f628e15225b0abda3e
title: "SDK Example: Add a Child Product to the Basket (Fall '20)"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/industries/cme/guides/comms-t-sdk-exampleadd-a-child-product-to-the-basketfall20-.md
canonical_url: https://developer.salesforce.com/docs/industries/cme/guide/comms-t-sdk-exampleadd-a-child-product-to-the-basketfall20-.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e5503c555232423c280104145a7836c2902035498c28facb5ab4b50e34052804
products:
  - Communications, Media, Energy and Utilities APIs (Managed Package)
  - Industries Developer Documentation
---
# SDK Example: Add a Child Product to the Basket (Fall '20)

Use the example SDK code in this topic to add a child product to a basket.

```nolang
// Instantiate the input object for AddToCartInput to specify parameters
const input = digitalCommerce.createAddToCartInput();
input.catalogCode = "Mobiles"; // use your Catalog Code
input.basketAction = "AddChildProduct"; // deleting an offer that was added to cart
input.basketKey = "01tf2000007Rb9JAAS"; // use your basketKey
input.actionParams = {
  rootProductCode: "iPhoneX", // use your rootProductCode
  parentLineKey: "c3a4590a2d231e7022e04e5eba539ead", // use your parentLineKey
  parentHierarchyPath: "01tf2000007Rb9JAAS", // use your parentHierarchyPath
  offer: "DeclineEquipmentProtection", // use your offer_code
  cartContextkey: "d80b2927f07938aefdc7e2e349e2ede7", // use your cartContextKey
  bundleContextKey: "c3a4590a2d231e7022e04e5eba539ead" // use your bundleContextKey};
input.customFields = ["customAttribute__c"]; // optional field which returns custom fields for given keys

// Invoke Basket API via method addToBasket()digitalCommerce
  .addToCart(input)
  .then(response => {
    Logger.info(
      "Vlocity digital commerce addToCart with basketAction=AddChildProduct for anonymous user: " +
        JSON.stringify(response)
    );
  })
  .catch(error => {
    Logger.info(
      "addToBasket with basketAction=AddChildProduct for anonymous user rest call failed" +
        error
    );
  });

```

Possible error conditions:

"AddToCartInput::getAPIPath() must have catalogCode."

"AddToCartInput::getAnonymousSiteRestUrl() must have catalogCode."

"AddToCartInput::getRequestPayload() must have basketAction."

"AddToCartInput::getRequestPayload() must have rootProductCode when basketAction is 'AddChildProduct'."

"AddToCartInput::getRequestPayload() must have parentLineKey when basketAction is 'AddChildProduct'."

"AddToCartInput::getRequestPayload() must have parentHierarchyPath when basketAction is 'AddChildProduct'."

"AddToCartInput::getRequestPayload() must have offer when basketAction is 'AddChildProduct'."

"AddToCartInput::getRequestPayload() must have cartContextkey when basketAction is 'AddChildProduct'."

"AddToCartInput::getRequestPayload() must have bundleContextKey when basketAction is 'AddChildProduct'."
