Skip to main content

Version: v1

Get Cart

Retrieves the cart associated with a specific customer using their unique identifier.


HTTP Method & Endpoint​

GET | /cart/customer/{customerId}


Request​

Path Parameters​

ParameterTypeRequiredDescription
customerIdStringYesUnique identifier of the customer. This is available in the customer object (specifically the id field) returned upon successful login.

Headers​

HeaderValueDescription
AuthorizationBearer {token}Authentication token (replace {token} with your actual token)
x-store-id{storeId}StoreId (replace {storeId} with your actual storeId)

Response Format​

Success Response (200 OK)​

FieldTypeDescription
messageStringStatus message indicating the result of the operation
dataArray (Cart)List of carts associated with the customer
sourceStringSource of the order data (e.g., "db")

Cart Object Properties​

FieldTypeDescription
idStringUnique identifier for the cart
storeIdStringStore ID for which the cart was created
customerIdStringCustomer's unique identifier
totalAmountNumberTotal amount payable for the items in the cart
itemsArray(Items)List of all items in the cart

Items Array Properties​

FieldTypeDescription
variantIdStringUnique identifier for the product variant
quantityNumberNumber of units in the cart
priceNumberPrice per unit (in paise)

Examples​

cURL​

curl --location 'https://dev-sfapi.unisouk.com/cart/customer/{customerId}' \
--header 'x-store-id: <STORE_ID>' \
--header 'Authorization: Bearer <TOKEN>'

JavaScript (React)​

import axios from "axios";

const getCartsByCustomer = async (customerId) => {
try {
const response = await axios.get(`https://dev-sfapi.unisouk.com/cart/customer/${customerId}`, {
headers: {
Authorization: "Bearer <TOKEN>",
"x-store-id": "<STORE_ID>",
},
});

console.log("Carts fetched successfully:", response.data);
} catch (error) {
console.error("Error fetching carts:", error.response?.data || error.message);
}
};

// Example usage
getCartsByCustomer("customer_123");

Sample Response​

{
"message": "Carts Fetched Successfully",
"data": [
{
"id": "2342341293912313",
"storeId": "2342341293912313",
"customerId": "2342341293912313",
"totalAmount": 5000,
"items": [
{
"variantId": "2342341293912313",
"quantity": 5,
"price": 1000
}
]
}
],
"source": "db"
}

Error Responses​

Status CodeDescription
400Bad Request - Invalid customer ID format
401Unauthorized - Authentication token is missing or invalid
403Forbidden - Access to carts not allowed
404Not Found - No carts found for the specified customer
500Internal Server Error - Something went wrong on the server