Get Cart
Retrieves the cart associated with a specific customer using their unique identifier.
HTTP Method & Endpoint
GET | /cart/customer/{customerId}
Request
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
customerId | String | Yes | Unique identifier of the customer. This is available in the customer object (specifically the id field) returned upon successful login. |
Headers
| Header | Value | Description |
|---|---|---|
Authorization | Bearer {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)
| Field | Type | Description |
|---|---|---|
message | String | Status message indicating the result of the operation |
data | Array (Cart) | List of carts associated with the customer |
source | String | Source of the order data (e.g., "db") |
Cart Object Properties
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the cart |
storeId | String | Store ID for which the cart was created |
customerId | String | Customer's unique identifier |
totalAmount | Number | Total amount payable for the items in the cart |
items | Array(Items) | List of all items in the cart |
Items Array Properties
| Field | Type | Description |
|---|---|---|
variantId | String | Unique identifier for the product variant |
quantity | Number | Number of units in the cart |
price | Number | Price 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 Code | Description |
|---|---|
| 400 | Bad Request - Invalid customer ID format |
| 401 | Unauthorized - Authentication token is missing or invalid |
| 403 | Forbidden - Access to carts not allowed |
| 404 | Not Found - No carts found for the specified customer |
| 500 | Internal Server Error - Something went wrong on the server |