Adding a product to a cart
Learn how to add 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 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,
Ensure you obtain your access token during cart creation. For instructions on generating the access token, refer to Creating a cart.
Send a
POST /v1/shoppers/me/carts/active?productId={productId}
request to the/v1/shoppers/me/carts/active
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 underlineItem
and any components under thecomponent
object. See Update current cart query parameters for more details.
Here's a basic example using cURL:
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts
/active?productId={productId}' \
--header 'authorization: Basic {Your_API_Key}'\
A successful request returns a 200 OK
response.
{
"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
}
}
A successful request will return a 200 OK
response with cart details, including line items and pricing information.
Last updated