Skip to main content
POST
/
api
/
cart
/
sync
Update Cart Item
curl --request POST \
  --url https://api.example.com/api/cart/sync \
  --header 'Content-Type: application/json' \
  --data '
{
  "userId": 123,
  "items": [
    {
      "id": "<string>",
      "quantity": 123
    }
  ]
}
'
{
  "success": true,
  "data": {
    "id": 123,
    "userId": 123,
    "items": [
      {
        "id": 123,
        "productoId": 123,
        "quantity": 123,
        "producto": {}
      }
    ]
  },
  "error": "<string>"
}

Overview

Updates the quantity of an existing product in the user’s shopping cart. This endpoint uses the cart synchronization mechanism to modify item quantities.

Authentication

This endpoint requires authentication. Ensure the user is authorized to modify the cart.

Request Body

userId
number
required
The unique identifier of the user whose cart you want to modify
items
array
required
Array of all cart items with updated quantities
id
string
required
The product ID (as a string)
quantity
number
required
The new quantity for the product (must be greater than 0)

Cart Item Structure

Each cart item contains:
  • id: Product identifier (string format)
  • quantity: Number of units (positive integer)

Response

success
boolean
required
Indicates whether the request was successful
data
object
The complete updated cart object
id
number
Unique identifier for the cart
userId
number
The ID of the user who owns this cart
items
array
Array of all cart items with updated quantities
id
number
Unique identifier for the cart item
productoId
number
The product ID for this cart item
quantity
number
Updated quantity of the product
producto
object
Complete product details
error
string
Error message if the request fails

Example Request

Update Single Item Quantity

curl -X POST "https://api.pcfix.com/api/cart/sync" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": 123,
    "items": [
      {
        "id": "789",
        "quantity": 5
      },
      {
        "id": "456",
        "quantity": 1
      }
    ]
  }'

Update Multiple Items

curl -X POST "https://api.pcfix.com/api/cart/sync" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": 123,
    "items": [
      {
        "id": "789",
        "quantity": 3
      },
      {
        "id": "456",
        "quantity": 2
      },
      {
        "id": "321",
        "quantity": 4
      }
    ]
  }'

Example Response

Success Response

{
  "success": true,
  "data": {
    "id": 1,
    "userId": 123,
    "abandonedEmailSent": false,
    "items": [
      {
        "id": 45,
        "cartId": 1,
        "productoId": 789,
        "quantity": 5,
        "producto": {
          "id": 789,
          "name": "Gaming Mouse",
          "price": 49.99,
          "description": "High-performance gaming mouse"
        }
      },
      {
        "id": 46,
        "cartId": 1,
        "productoId": 456,
        "quantity": 1,
        "producto": {
          "id": 456,
          "name": "Mechanical Keyboard",
          "price": 129.99,
          "description": "RGB mechanical keyboard"
        }
      }
    ]
  }
}

Error Response

{
  "success": false,
  "error": "User ID required"
}

Error Codes

Status CodeDescription
200Item quantity updated successfully
400Invalid user ID or request body
401Unauthorized access
500Server error - Failed to sync cart

Important Notes

The sync endpoint replaces ALL cart items. To update an item’s quantity, you must include ALL cart items in the request with their current or updated quantities.
To effectively increase or decrease quantity:
  1. First, fetch the current cart using GET /api/cart/:userId
  2. Modify the quantity of the desired item(s)
  3. Send all items back with the updated quantities

Quantity Updates

  • Quantities must be positive integers (greater than 0)
  • To remove an item, omit it from the items array (see Remove Item documentation)
  • Setting quantity to 0 will not remove the item; you must exclude it from the array
  • The abandonedEmailSent flag is reset to false when quantities are updated
  • Invalid product IDs are automatically filtered out during sync

Build docs developers (and LLMs) love