---
title: "Add item or update item quantity"
method: POST
path: "/ecommerce/cart/item/{productId}"
tags: ["🛒 Ecommerce"]
---

# Add item or update item quantity

`POST /ecommerce/cart/item/{productId}`

The API allows users to add a product to their cart or update the quantity of an already added product.

The frontend can send a request to this API, passing the `productId` as a path variable and the desired `quantity` as a number in the request body.

This API handles both adding new products to the cart and updating the quantity of existing products, providing a convenient way for users to manage their shopping cart.
E.g. If user has `4` products already in cart and if user click on `add more` button frontend should send quantity as `5` in the same api.

_**NOTES:**_ 

_Quanity that is passed in the request body will be assigned directly and will be treated as a new quantity for the respective product._

_Minimum quantity should be 1. Once user decrements it from 1, instead of sending 0 call remove item from cart api._

## Request body

- object
  - `quantity` string

## Response `200`

Add item or update item quantity

- object
  - `data` object
    - `_id` string
    - `cartTotal` number
    - `discountedTotal` number
    - `items` object[]
      - `_id` string
      - `coupon` unknown
      - `product` object
        - `__v` number
        - `_id` string
        - `category` string
        - `createdAt` string
        - `description` string
        - `mainImage` object
          - `_id` string
          - `localPath` string
          - `url` string
        - `name` string
        - `owner` string
        - `price` number
        - `stock` number
        - `subImages` object[]
          - `_id` string
          - `localPath` string
          - `url` string
        - `updatedAt` string
      - `quantity` number
  - `message` string
  - `statusCode` number
  - `success` boolean

---

[API](https://skmtc.net/hiteshchoudhary-ssesph/apis/freeapi.md) · [All operations](https://skmtc.net/hiteshchoudhary-ssesph/apis/freeapi/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/hiteshchoudhary-ssesph/freeapi/revisions/a9f3a290e4dc/schema)
