Creating or updating a cart
Learn how to create or update a cart.
Managing a cart is crucial for providing a seamless shopping experience. The process involves interacting with the Commerce API, whether creating a new cart or updating an existing one. This guide will cover the API requests and responses needed to create or update a cart successfully. Follow along to ensure your cart operations are smooth and efficient. If you want to add a gift to a cart, see Gifting.
Creating a cart
Creating a cart involves several steps, from obtaining an access token to verifying the cart's creation. This guide will walk you through the necessary API requests and responses to ensure a successful cart creation process.
To create a cart:
Send a
POST /oauth20/token
request to obtain an access token. You must include this token in all subsequent cart interactions.After receiving the token, verify the cart creation by sending a
GET /v1/shoppers/me/carts/active
request. Replace{Your_API_Key}
with your actual access token.
You can use cURL for this process, as shown below:
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts/active' \
--header 'Content-Type: application/json' \
--header 'authorization: Basic {Your_API_Key}\
A successful request returns a 200 OK
response, confirming the creation of the cart with various URIs for further interactions, such as managing payment methods and submitting the cart.
Updating a cart
Updating an existing cart allows you to add various elements such as products, coupon codes, billing, and shipping addresses. Below, you'll find a comprehensive guide on how to update your cart using cURL effectively. Ensure you have the API key and permission to modify the cart details.
You can use the POST /v1/shoppers/me/carts/active
resource to add products, coupon codes, billing/shipping addresses, and offers to a customer's cart. You can leverage all of the resources contained in the Cart to modify specific cart data elements. See the cart query parameters for more information.
Required: To pass customer credit card information through the Cart resource, you need a level 3 API key, a legal/contract amendment, and PCI documentation. Contact your Account Manager if you are interested in this capability.
To update a cart:
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
request. Replace{Your_API_Key}
with your actual API key. Include the necessary data parameters to modify the cart's contents as required. This allows you to add products, coupon codes, billing/shipping addresses and offers to a customer's cart.
You can use cURL for this process, as shown below:
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/carts/active' \
--header 'Content-Type: application/json' \
--header 'authorization: Basic {Your_API_Key}\
--data-raw '{
"cart": {
"ipAddress": "10.24.2.28",
"customAttributes": {
"attribute": [
{
"name": "name",
"value": "string",
"type": "string"
}
]
},
"suppressOrderConfirmationEmail": true,
"lineItems": {
"lineItem": [
{
"quantity": "1",
"product": {
"id": 1234
},
"customAttributes": {
"attribute": [
{
"name": "name",
"value": "string",
"type": "string"
}
]
}
}
]
},
"billingAddress": {
"uri": "https://api.digitalriver.com/v1/shoppers/me/address/47278020023",
"relation": "https://developers.digitalriver.com/v1/shoppers/AddressesResource",
"id": "billingAddress",
"firstName": "Automation",
"lastName": "Tester",
"companyName": "Digital River",
"line1": "PO BOX 6930",
"line2": "123",
"line3": "Suite Line 3",
"city": "Waconia",
"countrySubdivision": "MN",
"postalCode": "5387.0",
"country": "US",
"countryName": "United States",
"phoneNumber": "099-222-44454",
"emailAddress": "[email protected]",
"countyName": "Hennepin",
"phoneticFirstName": "クリス",
"phoneticLastName": "ミラー",
"division": "製品開発",
"title": "M"
},
"shippingAddress": {
"uri": "https://api.digitalriver.com/v1/shoppers/me/address/47278020023",
"relation": "https://developers.digitalriver.com/v1/shoppers/AddressesResource",
"id": "shippingAddress",
"firstName": "Automation",
"lastName": "Tester",
"companyName": "Digital River",
"line1": "PO BOX 6930",
"line2": "123",
"line3": "Suite Line 3",
"city": "Waconia",
"countrySubdivision": "MN",
"postalCode": "5387.0",
"country": "US",
"countryName": "United States",
"phoneNumber": "099-222-44454",
"countyName": "Hennepin",
"emailAddress": "[email protected]",
"phoneticFirstName": "クリス",
"phoneticLastName": "ミラー",
"division": "製品開発"
},
"termsOfSalesAcceptance": "true",
"chargeType": "moto",
"organizationId": "digitalriver12345"
}
}'
A successful request returns a 200 OK
response, confirming the updated cart details, including line items, pricing, addresses, etc.
Additional information
For additional information on updating a cart, see the following topics:
Last updated
Was this helpful?