# Adding a product to a cart

This section guides you through adding a product to a cart using the Commerce API. By making a POST request to the specified endpoint with the appropriate product identifier, you can seamlessly integrate the capability of adding products to a shopper's cart within your application.

See [Gifting ](/commerce-api/shopper-apis/cart/creating-or-updating-a-cart/adding-a-product-to-a-cart/gifting.md)for details if you want to add a gift product to the cart.

## Add a product to a cart using the product identifier

To add a product to a cart using the product identifier,&#x20;

1. Ensure you obtain your access token during cart creation. For instructions on generating the access token, refer to [Creating a cart](/commerce-api/shopper-apis/cart/creating-or-updating-a-cart.md#creating-a-cart).
2. Send a [`POST /v1/shoppers/me/carts/active?productId={productId}`](https://docs.digitalriver.com/commerce-api-references/shopper-apis/cart/carts#v1-shoppers-me-carts-active-1) request. Replace `{productId}` with the actual product identifier and `{Your_API_Key}` with your API key. For product combinations, replace the `{productId`} with the combination product's identifier. The response will detail the product information under `lineItem` and any components under the `component` object.&#x20;

Here's a basic example using cURL:

{% tabs %}
{% tab title="cURL" %}

```javascript
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts
/active?productId={productId}' \
--header 'authorization: Basic {Your_API_Key}'\
```

{% endtab %}

{% tab title="200 OK response" %}
A successful request returns a `200 OK` response.

```json
{
    "cart": {
        "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active",
        "paymentMethods": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/payment-methods"
        },
        "webCheckout": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/web-checkout"
        },
        "id": 278666810197,
        "lineItems": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items",
            "lineItem": [
                {
                    "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items/14052737700",
                    "id": 14052737700,
                    "quantity": 1,
                    "product": {
                        "uri": "https://api.digitalriver.com/v1/shoppers/me/products/8027217700",
                        "displayName": "Combination Product",
                        "thumbnailImage": null
                    },
                    "pricing": {
                        "listPrice": {
                            "currency": "USD",
                            "value": 36
                        },
                        "listPriceWithQuantity": {
                            "currency": "USD",
                            "value": 36
                        },
                        "salePriceWithQuantity": {
                            "currency": "USD",
                            "value": 36
                        },
                        "formattedListPrice": "$36.00",
                        "formattedListPriceWithQuantity": "$36.00",
                        "formattedSalePriceWithQuantity": "$36.00",
                        "productTax": {
                            "currency": "USD",
                            "value": 0
                        },
                        "shippingTax": {
                            "currency": "USD",
                            "value": 0
                        },
                        "feeTax": {
                            "currency": "USD",
                            "value": 0
                        },
                        "taxRate": 0.08525,
                        "importTax": {
                            "currency": "USD",
                            "value": 0
                        },
                        "formattedImportTax": "$0.00",
                        "importDuty": {
                            "currency": "USD",
                            "value": 0
                        },
                        "formattedImportDuty": "$0.00"
                    },
                    "components": {
                        "lineItem": [
                            {
                                "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items/14052737700",
                                "id": 14052737700,
                                "quantity": 1,
                                "product": {
                                    "uri": "https://api.digitalriver.com/v1/shoppers/me/products/257734900",
                                    "displayName": "Free trial product",
                                    "thumbnailImage": null,
                                    "recurringSubscriptionInfo": {
                                        "autoRenewal": "true",
                                        "termUnit": "WEEK",
                                        "termLength": "1"
                                    }
                                },
                                "pricing": {
                                    "listPrice": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "listPriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "salePriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedListPrice": "$0.00",
                                    "formattedListPriceWithQuantity": "$0.00",
                                    "formattedSalePriceWithQuantity": "$0.00",
                                    "productTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "shippingTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "feeTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "taxRate": 0.08525,
                                    "importTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportTax": "$0.00",
                                    "importDuty": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportDuty": "$0.00"
                                }
                            },
                            {
                                "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items/14052747700",
                                "id": 14052747700,
                                "quantity": 1,
                                "product": {
                                    "uri": "https://api.digitalriver.com/v1/shoppers/me/products/5505627700",
                                    "displayName": "AK123_Physical",
                                    "thumbnailImage": null
                                },
                                "pricing": {
                                    "listPrice": {
                                        "currency": "USD",
                                        "value": 17
                                    },
                                    "listPriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 17
                                    },
                                    "salePriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 17
                                    },
                                    "formattedListPrice": "$17.00",
                                    "formattedListPriceWithQuantity": "$17.00",
                                    "formattedSalePriceWithQuantity": "$17.00",
                                    "productTax": {
                                        "currency": "USD",
                                        "value": 1.45
                                    },
                                    "shippingTax": {
                                        "currency": "USD",
                                        "value": 4.26
                                    },
                                    "feeTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "taxRate": 0.08525,
                                    "importTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportTax": "$0.00",
                                    "importDuty": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportDuty": "$0.00"
                                }
                            },
                            {
                                "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/line-items/14052757700",
                                "id": 14052757700,
                                "quantity": 1,
                                "product": {
                                    "uri": "https://api.digitalriver.com/v1/shoppers/me/products/6686217700",
                                    "displayName": "Auto_Monthly_Sub",
                                    "thumbnailImage": null,
                                    "recurringSubscriptionInfo": {
                                        "autoRenewal": "true",
                                        "termUnit": "MONTH",
                                        "termLength": "1"
                                    }
                                },
                                "pricing": {
                                    "listPrice": {
                                        "currency": "USD",
                                        "value": 19
                                    },
                                    "listPriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 19
                                    },
                                    "salePriceWithQuantity": {
                                        "currency": "USD",
                                        "value": 19
                                    },
                                    "formattedListPrice": "$19.00",
                                    "formattedListPriceWithQuantity": "$19.00",
                                    "formattedSalePriceWithQuantity": "$19.00",
                                    "productTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "shippingTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "feeTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "taxRate": 0,
                                    "importTax": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportTax": "$0.00",
                                    "importDuty": {
                                        "currency": "USD",
                                        "value": 0
                                    },
                                    "formattedImportDuty": "$0.00"
                                }
                            }
                        ]
                    }
                }
            ]
        },
        "totalItemsInCart": 3,
        "businessEntityCode": "DR_INC-ENTITY",
        "billingAddress": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/billing-address"
        },
        "shippingAddress": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/shipping-address"
        },
        "payment": {},
        "paymentSession": {
            "id": "f3e53825-3d20-4c40-afb8-1cde7bdb3a3b",
            "clientSecret": "f3e53825-3d20-4c40-afb8-1cde7bdb3a3b_ef9cb4c1-f56c-4535-bd57-1a313c2f006d",
            "status": "requires_source"
        },
        "shippingMethod": {
            "code": 8046100,
            "description": "2 business days"
        },
        "shippingOptions": {
            "uri": "https://api.digitalriver.com/v1/shoppers/me/carts/active/shipping-options"
        },
        "taxInclusive": "false",
        "landedCostState": "NOT_ELIGIBLE",
        "pricing": {
            "subtotal": {
                "currency": "USD",
                "value": 36
            },
            "discount": {
                "currency": "USD",
                "value": 0
            },
            "shippingAndHandling": {
                "currency": "USD",
                "value": 50
            },
            "importTaxAndDuty": {
                "currency": "USD",
                "value": 0
            },
            "tax": {
                "currency": "USD",
                "value": 5.71
            },
            "orderTotal": {
                "currency": "USD",
                "value": 91.71
            },
            "formattedSubtotal": "$36.00",
            "formattedDiscount": "$0.00",
            "formattedShippingAndHandling": "$50.00",
            "formattedImportTaxAndDuty": "$0.00",
            "formattedTax": "$5.71",
            "formattedOrderTotal": "$91.71"
        },
        "termsOfSalesAcceptance": null
    }
}
```

{% endtab %}
{% endtabs %}

A successful request will return a `200 OK` response with cart details, including line items and pricing information.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalriver.com/commerce-api/shopper-apis/cart/creating-or-updating-a-cart/adding-a-product-to-a-cart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
