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
getCartquery with ID → Get existing cart - Use
getCartquery 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
}
}
}
}
{
"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":"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 } } } }","variables":{"id":"{CART_ID}","channelId":"{CHANNEL_ID}","languageId":"{LANGUAGE_ID}","marketId":"{MARKET_ID}"}}'
The
channelId, languageId, and marketId arguments are optional and can be left out to use default values.Response example
200 OKresponse.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 OKresponse.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:
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 docs
- Add items: Add product to cart
- Duplicate cart: Clone a cart
- Complete purchase: Checkout headless cart
Related
Activate promo code on cartAdd custom data to cartAdd product to cartCheck out headless cartClone a cartShow shipping/payment optionsGet cartUse external payment frameUse external shipping frameUse multi-market supportGetCart