Skip to main content
POST
/
cart
Add item to cart
curl --request POST \
  --url https://store.salesive.com/api/v1/cart \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-shop-id: <api-key>' \
  --data '
{
  "productId": "<string>",
  "variantId": "<string>",
  "quantity": 1
}
'
{
  "status": 123,
  "success": true,
  "message": "<string>",
  "data": {
    "_id": "<string>",
    "user": "<string>",
    "shop": "<string>",
    "items": [
      {
        "name": "<string>",
        "image": "<string>",
        "price": 123,
        "quantity": 2,
        "product": {
          "_id": "<string>",
          "id": "<string>",
          "name": "<string>",
          "images": [
            "<string>"
          ],
          "price": 123,
          "promoPrice": 123,
          "sku": "<string>",
          "parentProductId": "<string>",
          "variantAttributes": {}
        },
        "variant": "<string>",
        "sku": "<string>",
        "variantAttributes": {}
      }
    ],
    "totalPrice": 123,
    "createdAt": "2023-11-07T05:31:56Z",
    "updatedAt": "2023-11-07T05:31:56Z"
  }
}

Request

POST /cart
Authorization: Bearer {{token}}
x-shop-id: {{shopId}}
Content-Type: application/json

{
  "productId": "68e5bb463a1fc56a8ac150bf",
  "quantity": 2
}

Headers

HeaderTypeDescription
AuthorizationstringProvide the customer token as Bearer <jwt>.
x-shop-idstringIdentify the shop that owns the cart.
Content-TypestringAlways set to application/json.

Body parameters

FieldTypeRequiredDescription
productIdstringYesProduct identifier to add.
variantIdstringNoVariant identifier. Include it to add a specific variant line item.
quantityintegerNoQuantity to add. Defaults to 1.

Successful response

{
  "status": 200,
  "success": true,
  "message": "Item added to cart",
  "data": {
    "_id": "68f98d77c8502e9619569c24",
    "items": [
      {
        "product": {
          "_id": "68e5bb463a1fc56a8ac150bf",
          "name": "Head phone",
          "price": 10000,
          "formattedPrice": "10000.00"
        },
        "quantity": 2
      },
      {
        "product": {
          "_id": "68e5c1303a1fc56a8ac151e2",
          "name": "Head phone",
          "price": 1,
          "sku": "HEAD-PHONE-1-A"
        },
        "quantity": 1
      }
    ],
    "totalPrice": 20001
  }
}

Error response

{
  "status": 404,
  "success": false,
  "message": "Product not found",
  "data": {}
}

Authorizations

Authorization
string
header
required

JWT issued by the Salesive Store API for authenticated shoppers.

x-shop-id
string
header
required

Optional storefront identifier sent as a header to scope responses to a specific shop. Try It requests remember this value once provided.

Headers

x-shop-id
string

Optional identifier that scopes responses to a specific storefront when the referer cannot be inferred.

Body

application/json
productId
string
required

Identifier of the product to add to the cart.

variantId
string

Optional identifier of the product variant to add.

quantity
integer
default:1

Quantity of the product or variant to add. Defaults to 1.

Required range: x >= 1

Response

Cart updated with the new item.

status
integer
required

HTTP status code returned by the API.

success
boolean
required

Indicates whether the request succeeded.

message
string
required

Human-readable response message.

data
object
required