Carts

Last updated 2026-05-20

Copy-ready shopping-cart JSON with products, totals, discount math, and per-user carts. Add, update, and delete requests. Live REST endpoint at /carts.

Carts

fetch('https://jsonexamples.com/carts')
  .then(res => res.json())
  .then(console.log);
Response
{
  "carts": [
    {
      "id": 1,
      "products": [
        {
          "id": 59,
          "title": "Spring and summershoes",
          "price": 20,
          "quantity": 3,
          "total": 60,
          "discountPercentage": 8.71,
          "discountedPrice": 55
        }
      ],
      "total": 2328,
      "discountedTotal": 1941,
      "userId": 97,
      "totalProducts": 5,
      "totalQuantity": 10
    }
    // 20 items
  ],
  "total": 20,
  "skip": 0,
  "limit": 20
}
fetch('https://jsonexamples.com/carts/1')
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 1,
  "products": [
    { "id": 59, "title": "Spring and summershoes", "price": 20, "quantity": 3 }
    // ...more products
  ],
  "total": 2328,
  "discountedTotal": 1941,
  "userId": 97,
  "totalProducts": 5,
  "totalQuantity": 10
}
// getting carts of user with id 5
fetch('https://jsonexamples.com/carts/user/5')
  .then(res => res.json())
  .then(console.log);
Response
{
  "carts": [
    {
      "id": 19,
      "products": [/* ... */],
      "total": 2492,
      "discountedTotal": 2140,
      "userId": 5,
      "totalProducts": 5,
      "totalQuantity": 14
    }
  ],
  "total": 1,
  "skip": 0,
  "limit": 1
}
  • Adding a new cart will not persist on the server.
  • Provide a userId and an array of products as objects with productId and quantity.
fetch('https://jsonexamples.com/carts/add', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    userId: 1,
    products: [
      { id: 1, quantity: 1 },
      { id: 50, quantity: 2 },
    ]
  })
})
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 21,
  "products": [
    { "id": 1, "title": "iPhone 9", "price": 549, "quantity": 1, "total": 549 },
    { "id": 50, "title": "Women Shoes", "price": 36, "quantity": 2, "total": 72 }
  ],
  "total": 621,
  "discountedTotal": 538,
  "userId": 1,
  "totalProducts": 2,
  "totalQuantity": 3
}
  • Pass merge: true to include old products when updating.
/* adding products in cart with id 1 */
fetch('https://jsonexamples.com/carts/1', {
  method: 'PUT', /* or PATCH */
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    merge: true,
    products: [
      { id: 1, quantity: 1 },
    ]
  })
})
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": "1",
  "products": [
    { "id": 1, "title": "iPhone 9", "price": 549, "quantity": 1 }
    // ...other old products
  ],
  "total": 3798,
  "discountedTotal": 3172,
  "userId": 97,
  "totalProducts": 6,
  "totalQuantity": 11
}
fetch('https://jsonexamples.com/carts/1', { method: 'DELETE' })
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 1,
  "userId": 97,
  "isDeleted": true,
  "deletedOn": /* ISOTime */
}

Related examples