Create Multiple Carts
Each customer can have multiple carts. Use the carts
API to create and update multiple carts.
The carts are distinct from one another. Shoppers can add different items to their carts. They can check out one of the carts without affecting the content or status of their other carts.
After the shopper checks out the cart, the cart remains available to the shopper. The cart is persistent and stays with the shopper after it is used.
You can also create and update carts to specify custom discounts. You can enable custom discounts when the discount_settings.custom_discounts_enabled
field is set to true
. Default is set from cart discount settings for the store. See Cart Settings.
POST
Create a Custom Cart
https://api.moltin.com/v2/carts
Creates a custom cart. Call this endpoint each time a customer creates a cart.
Parameters
Headers
Name | Required | Type | Description |
---|---|---|---|
Authorization | Required | string | The Bearer token required to get access to the API. |
x-moltin-customer-token | Optional | string | A customer token to be associated with the cart. |
Body
Name | Required | Type | Description |
---|---|---|---|
name | Required | string | The cart name provided by the customer. A cart name must contain 1 to 255 characters. You cannot use whitespace characters, but special characters are permitted. For more information, see the Safe Characters section. |
id | Optional | string | Custom identifier for the cart. Only a-zA-Z0-9_- symbols are allowed. |
description | Optional | string | The cart description. |
discount_settings.custom_discounts_enabled | Optional | boolean | This parameter enables custom discounts for a cart. When set to true , Elastic Path promotions will not be applied to the new carts. Default is set from cart discount settings for the store. See Cart Settings. |
Request example
Curl
curl -X POST https://api.moltin.com/v2/carts \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \'
-H "x-moltin-customer-token: XXXX" \'
-d $ {
"data": {
"name": "Bob’s cart",
"description": "For Holidays",
"discount_settings": {
"custom_discounts_enabled": true
}
}
}
JavaScript SDK
const customerToken = "XXXX";
const cartData = {
name: "Bob’s cart",
description: "For Holidays",
};
// Where `EPCC` is an authenticated client
await EPCC.Cart().CreateCart(cartData, customerToken);
Response example
201 Created
{
"data": {
"id": "f52eafaf-123e-4eee-9fa9-5c9b5c24b079",
"name": "My cart",
"description": "my first cart",
"type": "cart",
"links": {
"self": "https://api.moltin.com/carts/v2/carts/f52eafaf-123e-4eee-9fa9-5c9b5c24b079"
},
"meta": {
"display_price": {
"with_tax": {
"amount": 0,
"currency": "",
"formatted": "0"
},
"without_tax": {
"amount": 0,
"currency": "",
"formatted": "0"
},
"tax": {
"amount": 0,
"currency": "",
"formatted": "0"
}
},
"timestamps": {
"created_at": "2020-09-09T16:45:28Z",
"updated_at": "2020-09-09T16:45:28Z",
"expires_at": "2020-09-20T16:45:28Z"
}
},
"relationships": {
"items": {
"data": null
},
"customers": {
"data": [
{
"type": "customer",
"id": "9efd11e1-7f66-4581-a9a9-ed63d8ba2474"
}
]
}
}
}
}
PUT
Update a Cart
https://api.moltin.com/v2/carts/:reference
Updates cart properties for the specified cart (:reference)
.
Parameters
Path parameters
Name | Required | Type | Description |
---|---|---|---|
reference | Required | string | A custom reference for this cart created by you. |
Headers
Name | Required | Type | Description |
---|---|---|---|
Authorization | Required | string | The Bearer token required to get access to the API. |
Body
Name | Required | Type | Description |
---|---|---|---|
name | Optional | string | The cart name supplied by the customer. A cart name must contain between 1 and 255 characters. You cannot use whitespace characters, but special characters are permitted. For more information, see Safe Characters. |
description | Optional | string | The cart description. |
discount_settings.custom_discounts_enabled | Optional | boolean | This parameter enables custom discounts for a cart. When set to true , Elastic Path promotions will not be applied to the new carts. Default is set from cart discount settings for the store. See Cart Settings. |
Request example
Curl
curl -X PUT https://api.moltin.com/v2/carts/:cartID \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \'
-d $ {
"data": {
"name": "My cart",
"description": "my first cart"
"discounts": {
"custom_discounts_enabled": false
}
},
}
JavaScript SDK
const reference = "XXXX";
const customerToken = "XXXX";
const cartData = {
name: "Bob’s cart",
description: "For Holidays",
};
// Where `EPCC` is an authenticated client
await EPCC.Cart(reference).UpdateCart(cartData, customerToken);
Response example
200 OK
{
"data": {
"id": "df820a6e-ca10-457e-a7ac-f68d13b318dd",
"name": "my cart",
"description": "my first cart",
"type": "cart",
"discount_settings": {
"custom_discounts_enabled": false
},
"links": {
"self": "https://api.moltin.com/carts/v2/carts/df820a6e-ca10-457e-a7ac-f68d13b318dd"
},
"meta": {
"display_price": {
"with_tax": {
"amount": 12221,
"currency": "USD",
"formatted": "$122.21"
},
"without_tax": {
"amount": 12221,
"currency": "USD",
"formatted": "$122.21"
},
"tax": {
"amount": 0,
"currency": "USD",
"formatted": "$0.00"
}
},
"timestamps": {
"created_at": "2020-10-15T16:17:53Z",
"updated_at": "2020-10-15T16:20:55Z"
}
},
"relationships": {
"items": {
"data": [
{
"type": "cart_item",
"id": "615c4c0e-8184-4991-a5a9-eda5499fb558"
}
]
},
"customers": {
"data": [
{
"type": "customer",
"id": "9efd11e1-7f66-4581-a9a9-ed63d8ba2474"
}
]
}
}
}
}
Error Codes
You might encounter the following response codes, depending on the scenario:
400 Bad Request
-Blank name
- Thename
parameter is blank or contains whitespace characters. Specify a valid string.400 Bad Request
-Name with > 255 characters
- Strings must be less than or equal to 255 characters.400 Bad Request
-Odd characters
- Thename
parameter cannot contain whitespace characters. Unicode Transformation Format (UTF-8) characters are allowed.