Gen-Endpoint
Back to API List
Shopping Cart API
Manage shopping cart operations with session handling, item management, and checkout preparation.
E-commerce
Internal API - Hosted by this App
API Endpoints & Usage
Explore and interact with the available endpoints for the Shopping Cart API. These API routes are live! The paths shown below are relative to your application's base URL. For example, if this application is hosted at https://gen-endpoint.com, an endpoint path for this API, such as /api/cart/{sessionId}, would be accessible at https://gen-endpoint.com/api/cart/{sessionId}. You can use the "Try it out" section for each endpoint or use tools like curl, Postman, or your browser's address bar (for GET requests) to interact with them.
GET

/api/cart/{sessionId}

Get cart contents for session with item details and totals. Replace {sessionId} with an actual session ID (e.g., sess_123).

Show Static Examples

Example Response:

{
  "sessionId": "sess_123",
  "items": [
    {
      "id": "item_1",
      "productId": "prod_123",
      "name": "Wireless Headphones",
      "price": 99.99,
      "quantity": 2,
      "options": {
        "color": "black",
        "size": "standard"
      },
      "imageUrl": "https://placehold.co/100x100.png",
      "subtotal": 199.98,
      "addedAt": "2024-08-16T12:00:00Z"
    }
  ],
  "totals": {
    "subtotal": 199.98,
    "tax": 16,
    "shipping": 0,
    "discount": 0,
    "total": 215.98
  },
  "createdAt": "2024-08-16T12:00:00Z",
  "updatedAt": "2024-08-16T12:00:00Z",
  "expiresAt": "2024-08-17T12:00:00Z"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

POST

/api/cart/{sessionId}/items

Add an item to the cart. Replace {sessionId} with a session ID.

Show Static Examples

Example Request Body:

{
  "productId": "prod_456",
  "quantity": 1,
  "options": {"format": "paperback"}
}

Example Response:

{
  "success": true,
  "item": {
    "id": "item_randomId",
    "productId": "prod_456",
    "name": "JavaScript Book",
    "price": 29.99,
    "quantity": 1,
    "options": {
      "format": "paperback"
    },
    "imageUrl": "https://placehold.co/100x100.png",
    "subtotal": 29.99,
    "addedAt": "2024-08-17T10:00:00Z"
  },
  "cartTotal": 245.97,
  "itemCount": 3
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above.

GET

/api/cart/{sessionId}/items

List all items in the specified cart. Replace {sessionId} with a session ID.

Show Static Examples

Example Response:

{
  "items": [
    {
      "id": "item_1",
      "productId": "prod_123",
      "name": "Wireless Headphones",
      "price": 99.99,
      "quantity": 2,
      "options": {
        "color": "black"
      },
      "subtotal": 199.98
    }
  ],
  "itemCount": 2,
  "totals": {
    "subtotal": 199.98,
    "tax": 16,
    "shipping": 0,
    "discount": 0,
    "total": 215.98
  }
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

PUT

/api/cart/{sessionId}

Update cart metadata, e.g., apply a coupon code. Replace {sessionId} with a session ID.

Show Static Examples

Example Request Body:

{
  "couponCode": "SAVE10"
}

Example Response:

{
  "sessionId": "sess_123",
  "items": [
    {
      "id": "item_1",
      "name": "Wireless Headphones",
      "quantity": 2,
      "subtotal": 199.98
    }
  ],
  "totals": {
    "subtotal": 199.98,
    "tax": 16,
    "shipping": 0,
    "discount": 20,
    "total": 195.98
  },
  "couponCode": "SAVE10",
  "updatedAt": "2024-08-17T11:00:00Z"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above.

DELETE

/api/cart/{sessionId}

Clear all items from the cart. Replace {sessionId} with a session ID.

Show Static Examples

Example Response:

{
  "message": "Cart cleared successfully",
  "timestamp": "2024-08-17T11:05:00Z"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above.