Store Kit
Cart

Get Cart Items

Retrieve all items from the customer's cart

Get Cart Items

Retrieve all items from the customer's cart. This endpoint supports both authenticated customers and anonymous users through session tracking.

Endpoint

GET /v1/cart

Base URL: https://api.storekit.app

Authentication

Info: All API requests require authentication using an API key. Generate your API key from the StoreKit Dashboard under API Key Usage section.

Headers

HeaderTypeRequiredDescription
x-api-keystringyesYour API key from the StoreKit dashboard

Response

Success Response (200 OK)

{
  "success": true,
  "data": [
    {
      "id": "cmcoq5pj5000dzvn7ljm7v6u0",
      "quantity": 16,
      "addedAt": "2025-07-04T11:22:02.753Z",
      "productId": "cmc6n775m000dzvn0yngqb69s",
      "customerId": "cmcoq34z20004zvn7hqlfttgu",
      "product": {
        "id": "cmc6n775m000dzvn0yngqb69s",
        "name": "test",
        "description": "te",
        "price": 10,
        "stock": 0,
        "image": "",
        "status": "ACTIVE",
        "category": "clothing",
        "createdAt": "2025-06-21T19:39:22.226Z",
        "storeId": "cmbug7xjl000ezviur9su2gja"
      }
    }
  ],
  "count": 1,
  "message": "list of all cart items"
}

Response Fields

FieldTypeDescription
successbooleanIndicates if the request was successful
dataarrayArray of cart items
countnumberTotal number of items in the cart
messagestringResponse message

Cart Item Object

FieldTypeDescription
idstringUnique identifier for the cart item
quantitynumberNumber of items in the cart
addedAtstringISO timestamp when the item was added
productIdstringID of the product
customerIdstringID of the customer (null for anonymous users)
productobjectComplete product information

Product Object

FieldTypeDescription
idstringUnique identifier for the product
namestringProduct name
descriptionstringProduct description
pricenumberProduct price
stocknumberAvailable stock quantity
imagestringProduct image URL
statusstringProduct status (ACTIVE, INACTIVE)
categorystringProduct category
createdAtstringISO timestamp when the product was created
storeIdstringID of the store

Error Responses

Missing API Key (401)

{
  "error": "API key is required"
}

Invalid API Key (500)

{
  "error": "Internal server error"
}

Invalid Input Data (422)

{
  "success": false,
  "message": "Invalid input data"
}

Internal Server Error (500)

{
  "success": false,
  "message": "Failed to fetch cart items"
}

Code Examples

curl -X GET "https://api.storekit.app/v1/cart" \
  -H "x-api-key: sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402"
const response = await fetch("https://api.storekit.app/v1/cart", {
  method: "GET",
  headers: {
    "x-api-key":
      "sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402",
  },
});

const data = await response.json();

if (data.success) {
  console.log(`Found ${data.count} items in cart:`, data.data);
  
  // Calculate total price
  const totalPrice = data.data.reduce((sum, item) => 
    sum + (item.product.price * item.quantity), 0
  );
  console.log(`Total cart value: $${totalPrice}`);
} else {
  console.error("Error:", data.message);
}
import axios from "axios";

try {
  const response = await axios.get("https://api.storekit.app/v1/cart", {
    headers: {
      "x-api-key":
        "sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402",
    },
  });

  const { success, data, count, message } = response.data;

  if (success) {
    console.log(`Found ${count} items in cart:`, data);
    
    // Calculate total price
    const totalPrice = data.reduce((sum, item) => 
      sum + (item.product.price * item.quantity), 0
    );
    console.log(`Total cart value: $${totalPrice}`);
  } else {
    console.error("Error:", message);
  }
} catch (error) {
  if (error.response?.data?.error) {
    console.error("API Error:", error.response.data.error);
  } else {
    console.error("Request failed:", error.message);
  }
}
const https = require("https");

const options = {
  hostname: "api.storekit.app",
  port: 443,
  path: "/v1/cart",
  method: "GET",
  headers: {
    "x-api-key":
      "sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402",
  },
};

const req = https.request(options, (res) => {
  let data = "";

  res.on("data", (chunk) => {
    data += chunk;
  });

  res.on("end", () => {
    const result = JSON.parse(data);

    if (result.success) {
      console.log(`Found ${result.count} items in cart:`, result.data);
      
      // Calculate total price
      const totalPrice = result.data.reduce((sum, item) => 
        sum + (item.product.price * item.quantity), 0
      );
      console.log(`Total cart value: $${totalPrice}`);
    } else {
      console.error("Error:", result.message || result.error);
    }
  });
});

req.on("error", (error) => {
  console.error("Request failed:", error);
});

req.end();
import requests
import json

url = "https://api.storekit.app/v1/cart"
headers = {
    "x-api-key": "sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402"
}

try:
    response = requests.get(url, headers=headers)
    response.raise_for_status()

    data = response.json()

    if data.get('success'):
        print(f"Found {data['count']} items in cart:")
        
        total_price = 0
        for item in data['data']:
            product = item['product']
            item_total = product['price'] * item['quantity']
            total_price += item_total
            
            print(f"- {product['name']}: ${product['price']} x {item['quantity']} = ${item_total}")
        
        print(f"Total cart value: ${total_price}")
    else:
        print(f"Error: {data.get('message', data.get('error'))}")

except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.storekit.app/v1/cart",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "x-api-key: sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402"
    ],
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

$data = json_decode($response, true);

if ($httpCode === 200 && $data['success']) {
    echo "Found " . $data['count'] . " items in cart:\n";
    
    $totalPrice = 0;
    foreach ($data['data'] as $item) {
        $product = $item['product'];
        $itemTotal = $product['price'] * $item['quantity'];
        $totalPrice += $itemTotal;
        
        echo "- " . $product['name'] . ": $" . $product['price'] . " x " . $item['quantity'] . " = $" . $itemTotal . "\n";
    }
    
    echo "Total cart value: $" . $totalPrice . "\n";
} else {
    echo "Error: " . ($data['message'] ?? $data['error']) . "\n";
}
?>
$.ajax({
  url: "https://api.storekit.app/v1/cart",
  method: "GET",
  headers: {
    "x-api-key":
      "sk_live_be186797384f05ff038e1751e8ff9572cf8a05adfdba79abb7e8bcd165f2c402",
  },
  success: function (data) {
    if (data.success) {
      console.log(`Found ${data.count} items in cart:`, data.data);

      // Example: Display in UI
      $("#cart-count").text(data.count);
      $("#cart-items").empty();
      
      let totalPrice = 0;

      data.data.forEach(function (item) {
        const product = item.product;
        const itemTotal = product.price * item.quantity;
        totalPrice += itemTotal;

        $("#cart-items").append(`
          <div class="cart-item" data-id="${item.id}">
            <div class="product-info">
              <h4>${product.name}</h4>
              <p>${product.description}</p>
              <img src="${product.image}" alt="${product.name}" />
            </div>
            <div class="quantity-price">
              <span>Quantity: ${item.quantity}</span>
              <span>Price: $${product.price}</span>
              <span>Total: $${itemTotal}</span>
            </div>
            <small>Added: ${new Date(item.addedAt).toLocaleDateString()}</small>
          </div>
        `);
      });
      
      $("#cart-total").text(`$${totalPrice}`);
    } else {
      console.error("Error:", data.message);
      $("#cart-error").show().text(data.message);
    }
  },
  error: function (xhr, status, error) {
    const errorMessage = xhr.responseJSON?.error || xhr.responseJSON?.message || error;
    console.error("Request failed:", errorMessage);
    $("#cart-error").show().text(`Failed to load cart: ${errorMessage}`);
  },
});

Authentication & Session Management

This endpoint automatically handles both authenticated and anonymous users:

  • Authenticated users: Returns items from their customer account cart
  • Anonymous users: Returns items from their session-based cart tracked via cookies

No manual session management is required - the API handles this automatically through cookies.

Important Notes

  • Items are returned in descending order by addedAt (newest first)
  • Each cart item includes complete product information
  • For anonymous users, customerId will be null
  • Empty carts return an empty array with count: 0
  • API key is required for all requests and can be generated in your StoreKit Dashboard

Customer Context

Info: This endpoint uses customer identification middleware that tracks items by:

  • Authenticated users: Items are associated with their customerId
  • Guest users: Items are tracked by sessionId for the current browser session automatically

Status Codes

CodeDescription
200Successfully retrieved cart items
401Invalid or missing API key
422Invalid input data
500Internal server error