Clone a cart
Prerequisites
- Merchant API key
- Existing cart ID to clone
Goal
- Create a new cart by cloning an existing one
Architecture at a glance
- Use
cloneCartmutation → Get new cart ID → Continue shopping with cloned cart
APIs used
- Merchant API:
https://merchantapi.geins.io/graphql
Step-by-step
Clone an existing cart
Use the cloneCart mutation to create an exact copy of an existing cart:
Request example
mutation cloneCart(
$id: String!
$resetPromotions: Boolean,
$channelId: String,
$languageId: String,
$marketId: String
) {
cloneCart(
id: $id,
resetPromotions: $resetPromotions,
channelId: $channelId,
languageId: $languageId,
marketId: $marketId
) {
id
}
}
{
"Accept": "application/json",
"X-ApiKey": "{MERCHANT_API_KEY}"
}
{
"id": "{CART_ID}",
"channelId": "{CHANNEL_ID}",
"languageId": "{LANGUAGE_ID}",
"marketId": "{MARKET_ID}"
}
curl -X POST https://merchantapi.geins.io/graphql \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-ApiKey: {MERCHANT_API_KEY}" \
-d '{"query":"mutation cloneCart($id: String!, $resetPromotions: Boolean, $channelId: String, $languageId: String, $marketId: String) { cloneCart(id: $id, resetPromotions: $resetPromotions, channelId: $channelId, languageId: $languageId, marketId: $marketId) { id } }","variables":{"id":"{CART_ID}","channelId":"{CHANNEL_ID}","languageId":"{LANGUAGE_ID}","marketId":"{MARKET_ID}"}}'
channelId, languageId, and marketId arguments are optional and can be left out to use default values.Response example
200 OK{
"data": {
"cloneCart": {
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
}
}
}
Continue shopping with the cloned cart
You can now use the new id with getCart to get the newly created cart and continue shopping, add items, and proceed to checkout as usual.
Options
Reset promotions
When cloning a cart, you can choose to reset any applied promotions by setting the resetPromotions parameter to true in the cloneCart mutation. This will remove any applied promo code or price list prices from the cloned cart.
{
"id": "{CART_ID}",
"resetPromotions": true,
"channelId": "{CHANNEL_ID}",
"languageId": "{LANGUAGE_ID}",
"marketId": "{MARKET_ID}"
}
Channel, Language, and Market
The mutation also supports optional parameters for multi-market support:
channelId, languageId, and marketId in the "how to"-article about using multi-market support..Authenticated access
While authentication is not required for this mutation, including a JWT bearer token in the Authorization header can provide personalized results based on the authenticated user's context, for example personalized pricing.
To include authentication, add the JWT bearer token to your request headers:
"Authorization": "Bearer {JWT_TOKEN}"