How to

Get cart

Retrieve an existing cart or create a new one using Geins Merchant API

Prerequisites

  • Merchant API key

Goal

  • Retrieve an existing cart by ID
  • Create a new cart when no ID is provided

Architecture at a glance

  • Use getCart query with ID → Get existing cart
  • Use getCart query without ID → Create new cart

APIs used

  • Merchant API: https://merchantapi.geins.io/graphql

Step-by-step

Get an existing cart

Use the getCart query with a cart ID to retrieve an existing cart:

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

Request example

query getCart(
  $id: String
  $channelId: String
  $languageId: String
  $marketId: String
) {
  getCart(
    id: $id
    channelId: $channelId
    languageId: $languageId
    marketId: $marketId
  ) {
    id
    items {
      id
      skuId
      quantity
      product {
        name
      }
      unitPrice {
        regularPriceIncVat
      }
      totalPrice {
        regularPriceIncVat
      }
    }
    summary {
      total {
        regularPriceIncVat
      }
    }
  }
}
The channelId, languageId, and marketId arguments are optional and can be left out to use default values.

Response example

200 OK
response.json
{
  "data": {
    "getCart": {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "items": [
        {
          "id": "item-id-1",
          "skuId": {SKU_ID},
          "quantity": 2,
          "name": "Product Name",
          "unitPrice": {
            "regularPriceIncVat": 99.00
          },
          "totalPrice": {
            "regularPriceIncVat": 198.00
          }
        }
      ],
      "summary": {
        "total": {
          "regularPriceIncVat": 198.00
        }
      }
    }
  }
}

Create a new cart

To create a new cart, use the same getCart query but omit the id parameter or set it to null:

Request example

{
  "channelId": "{CHANNEL_ID}",
  "languageId": "{LANGUAGE_ID}",
  "marketId": "{MARKET_ID}"
}

Response example

200 OK
response.json
{
  "data": {
    "getCart": {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "items": [],
      "summary": {
        "total": {
          "regularPriceIncVat": 0.00
        }
      }
    }
  }
}

Options

Multi-market support

The query supports optional parameters for multi-market configurations:

Read more about channelId, languageId, and marketId in the multi-market support guide.

Authenticated access

While authentication is not required for this query, 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