cart.addToCart

This method is used to add items to a Cart.

Version

v2

Arguments

This method has the path /cart/<version>/cart.addToCart and follows the MicroBase API calling conventions.

Argument Required Type Example Description
cartId yes String H19PRsec The id of the Cart to add entries.
items yes Object List - The list of entries to add to the Cart.

Items

Argument Required Type Example Description
productId yes String By2ZWfAPnV The Product Id.
quantity yes Number 1 The quantity of product to add to the Cart.
warehouseId yes String 001 The id of the warehouse to pick products.

Response

Returns the complete cart:

{
  "ok": true,
  "cart": {
    "id": "H19PRsec",
    "status": "ACTIVE",
    "customerId": "ANON",
    "currency": "USD",
    "channel": "WEB",
    "expirationTime": "2018-05-31T15:12:54.096Z",
    "items": [
      {
        "id": "HJsKZud1X",
        "productId": "rylW3KZvJX",
        "taxCode": "default",
        "isNetPrice": false,
        "title": "0001 - Gel Noosa Tri 11 (ASics)",
        "quantity": 3,
        "price": {
          "amount": 11900,
          "currency": "USD",
          "precision": 2
        },
        "taxes": [
          {
            "beforeTax": {
              "amount": 35700,
              "currency": "USD",
              "precision": 2
            },
            "tax": {
              "amount": 7497,
              "currency": "USD",
              "precision": 2
            },
            "taxDetail": "IVA 21%"
          }
        ],
        "discounts": [],
        "reserves": []
      }
    ],
    "promotions": {
      "almostFulfilledPromos": [],
      "fulfilledPromos": [],
      "ok": true
    },
    "taxes": {
      "ok": true,
      "beforeTax": {
        "amount": 35700,
        "currency": "USD",
        "precision": 2
      },
      "tax": {
        "amount": 7497,
        "currency": "USD",
        "precision": 2
      }
    }
  }
}

Price selection

The Product can have several Prices, each one with diferent fields, some of the mandatory like amount and currency and some of them optional like country, customerType, channel and validFrom/validUntil.

When adding Products to the Cart the selection of the Price is made calculating a score for each data coincidence:

The currency must always coincide.

if price.country == customer.country => score = score +1

if price.channel == cart.channel => score = score +2

if price.customerType in customer.tags => score = score +4

In case of score tie, a valid period will win.

Errors

Expected errors that this method could return. Some errors return additional data.

Error Data Description
cart_not_found - The Cart was not found
max_quantity_per_product_exceeded productId, requestedQuantity, maxQuantityAllowed The requested quantity exceeds the limit.
max_number_of_entries_exceeded requestedEntries, maxEntriesAllowed The requested entries exceeds the limit.
product_not_found productId The Product was not found.
product_discontinued productId The Product is discontinued.
validation_error The data causing the error Some validation error

Example

curl --request POST \
  --url http://localhost:3000/services/cart/v1/cart.addToCart?cartId=H19PRsec \
  --header 'authorization: Bearer xxxxx...' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{ "items": [
              {"productId": "By2ZWfAPnV", "quantity": 1, "warehouseId": "001"} \                                                 
          ]}'