Check out headless cart
Overview
Learn how to create a cart, add items to it, and then complete the checkout process using Geins Merchant API.
Prerequisites
- Merchant API key
- Known SKU to add to the cart
- Available shipping ID
- Available payment ID
Goal
- Create a new cart
- Add products to the cart
- Complete the checkout process and place an order
Architecture at a glance
- Create cart → Add items to cart → Place order → Get order confirmation
Step-by-step
Create a new cart
Start by creating a new cart using the getCart query. When no cart ID is provided, a new cart will be created automatically.
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
unitPrice {
regularPriceIncVat
}
totalPrice {
regularPriceIncVat
}
}
summary {
total {
regularPriceIncVat
}
}
}
}
{
"Accept": "application/json",
"X-ApiKey": "{MERCHANT_API_KEY}"
}
{
"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 unitPrice { regularPriceIncVat } totalPrice { regularPriceIncVat } } summary { total { regularPriceIncVat } } } }","variables":{"channelId":"{CHANNEL_ID}","languageId":"{LANGUAGE_ID}","marketId":"{MARKET_ID}"}}'
Response example
200 OK{
"data": {
"getCart": {
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"items": [],
"summary": {
"total": { ... },
}
}
}
}
Add items to the cart
Now add products to your cart using the addToCart mutation. You'll need the cart ID from step 1 and a valid SKU ID (as an integer).
Request example
mutation addToCart(
$id: String!
$item: CartItemInputType!
$channelId: String
$languageId: String
$marketId: String
) {
addToCart(
id: $id
item: $item
channelId: $channelId
languageId: $languageId
marketId: $marketId
) {
id
items {
id
skuId
quantity
unitPrice {
regularPriceIncVat
}
totalPrice {
regularPriceIncVat
}
}
summary {
total {
regularPriceIncVat
}
}
}
}
{
"Accept": "application/json",
"X-ApiKey": "{MERCHANT_API_KEY}"
}
{
"id": "{CART_ID}",
"item": {
"skuId": {SKU_ID},
"quantity": 2
},
"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 addToCart($id: String!, $item: CartItemInputType!, $channelId: String, $languageId: String, $marketId: String) { addToCart(id: $id, item: $item, channelId: $channelId, languageId: $languageId, marketId: $marketId) { id items { id skuId quantity unitPrice { regularPriceIncVat } totalPrice { regularPriceIncVat } } summary { total { regularPriceIncVat } } } }","variables":{"id":"{CART_ID}","item":{"skuId":{SKU_ID},"quantity":2},"channelId":"{CHANNEL_ID}","languageId":"{LANGUAGE_ID}","marketId":"{MARKET_ID}"}}'
Response example
200 OK{
"data": {
"addToCart": {
"id": "{CART_ID}",
"items": [
{
"id": "xxx",
"skuId": {SKU_ID},
"quantity": 2,
"unitPrice": {
"regularPriceIncVat": 20.00,
},
"totalPrice": {
"regularPriceIncVat": 40.00,
}
}
],
"summary": {
"total": { ... },
}
}
}
}
Place the order
Complete the checkout process by placing the order using the placeOrder mutation. You'll need the cart ID and checkout information including shipping IDs.
Request example
mutation placeOrder(
$cartId: String!
$checkout: CheckoutInputType!
$channelId: String
$languageId: String
$marketId: String
) {
placeOrder(
cartId: $cartId
checkout: $checkout
channelId: $channelId
languageId: $languageId
marketId: $marketId
) {
orderId
publicId
}
}
{
"Accept": "application/json",
"X-ApiKey": "{MERCHANT_API_KEY}"
}
{
"cartId": "{CART_ID}",
"checkout": {
"paymentId": {PAYMENT_ID},
"shippingId": {SHIPPING_ID},
"email": "{USER_EMAIL}",
"billingAddress": {
"firstName": "John",
"lastName": "Doe",
"addressLine1": "Street Address 123",
"city": "Stockholm",
"zip": "12345",
"country": "SE"
},
},
"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 placeOrder($cartId: String!, $checkout: CheckoutInputType!, $channelId: String, $languageId: String, $marketId: String) { placeOrder(cartId: $cartId, checkout: $checkout, channelId: $channelId, languageId: $languageId, marketId: $marketId) { orderId publicId } }","variables":{"cartId":"{CART_ID}","checkout":{"paymentId":{PAYMENT_ID},"shippingId":{SHIPPING_ID},"email":"{USER_EMAIL}","billingAddress":{"firstName":"John","lastName":"Doe","addressLine1":"Street Address 123","city":"Stockholm","zip":"12345","country":"SE"}},"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": {
"placeOrder": {
"orderId": "order-id-12345",
"publicId": "ORD-2025-001234",
}
}
}
Options
Multi-market support
All mutations and queries support optional parameters for multi-market functionality:
channelId: Target specific sales channelslanguageId: Set content languagemarketId: Target specific markets
channelId, languageId, and marketId in the "how to"-article about using multi-market support.Authenticated access
While authentication is not required for these mutations, including a JWT bearer token in the Authorization header can provide personalized results based on the authenticated user's context, for example personalized pricing and pre-filled user information.
To include authentication, add the JWT bearer token to your request headers:
"Authorization": "Bearer {JWT_TOKEN}"
Common pitfalls
- Ensure the SKU ID exists and is available
- Verify that the shipping ID is a valid integer for your merchant setup
- Check that the cart has items before attempting to place an order
- Note that
addToCartaccepts a single item, not an array - call it multiple times for multiple items