Skip to main content
POST
/
api
/
cart
/
sync
Remove Item from Cart
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

Removes a product from the user’s shopping cart. This endpoint uses the cart synchronization mechanism - to remove an item, simply exclude it from the items array.

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 cart items to keep. Exclude the item(s) you want to remove.
id
string
required
The product ID (as a string)
quantity
number
required
The quantity of the product

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 remaining cart items (after removal)
id
number
Unique identifier for the cart item
productoId
number
The product ID for this cart item
quantity
number
Quantity of the product
producto
object
Complete product details
error
string
Error message if the request fails

Example Request

Remove Single Item

If the cart currently has items with IDs “789” and “456”, and you want to remove item “456”:
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": 2
      }
    ]
  }'

Remove Multiple Items

To remove multiple items, simply exclude them from the array:
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": 2
      }
    ]
  }'

Clear Entire Cart

To remove all items from the cart, send an empty items array:
curl -X POST "https://api.pcfix.com/api/cart/sync" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": 123,
    "items": []
  }'

Example Response

Success Response

{
  "success": true,
  "data": {
    "id": 1,
    "userId": 123,
    "abandonedEmailSent": false,
    "items": [
      {
        "id": 45,
        "cartId": 1,
        "productoId": 789,
        "quantity": 2,
        "producto": {
          "id": 789,
          "name": "Gaming Mouse",
          "price": 49.99,
          "description": "High-performance gaming mouse"
        }
      }
    ]
  }
}

Empty Cart Response

{
  "success": true,
  "data": {
    "id": 1,
    "userId": 123,
    "abandonedEmailSent": false,
    "items": []
  }
}

Error Response

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

Error Codes

Status CodeDescription
200Item removed 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 remove an item, send a request with all items you want to KEEP, excluding the one(s) you want to remove.
Removal workflow:
  1. Fetch the current cart using GET /api/cart/:userId
  2. Filter out the item(s) you want to remove from the items array
  3. Send the remaining items back to the sync endpoint

Removal Strategies

Remove by exclusion: The recommended approach is to exclude items you want to remove from the items array Clear cart: Send an empty items array to remove all items at once Validation: Only valid, non-deleted products are kept in the cart. Invalid product IDs are automatically filtered out Side effects: The abandonedEmailSent flag is reset to false when cart contents change

Build docs developers (and LLMs) love