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
Header | Type | Required | Description |
---|---|---|---|
x-api-key | string | yes | Your 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
Field | Type | Description |
---|---|---|
success | boolean | Indicates if the request was successful |
data | array | Array of cart items |
count | number | Total number of items in the cart |
message | string | Response message |
Cart Item Object
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the cart item |
quantity | number | Number of items in the cart |
addedAt | string | ISO timestamp when the item was added |
productId | string | ID of the product |
customerId | string | ID of the customer (null for anonymous users) |
product | object | Complete product information |
Product Object
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the product |
name | string | Product name |
description | string | Product description |
price | number | Product price |
stock | number | Available stock quantity |
image | string | Product image URL |
status | string | Product status (ACTIVE, INACTIVE) |
category | string | Product category |
createdAt | string | ISO timestamp when the product was created |
storeId | string | ID 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
Code | Description |
---|---|
200 | Successfully retrieved cart items |
401 | Invalid or missing API key |
422 | Invalid input data |
500 | Internal server error |