How to

Clone a cart

Duplicate an existing cart for a seamless shopping experience using Geins Merchant API

Prerequisites

  • Merchant API key
  • Existing cart ID to clone

Goal

  • Create a new cart by cloning an existing one

Architecture at a glance

  • Use cloneCart mutation → 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:

Try it out in the GraphQL Playground using the query, headers and variables below.

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
  }
}
The channelId, languageId, and marketId arguments are optional and can be left out to use default values.

Response example

200 OK
response.json
{
  "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.

query-variables.json
{
  "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:

Read more about 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}"
Read more about obtaining and using JWT tokens in the guide about the authentication flow.
Related