cart.create
This method is used to create a new Cart or merge an anonymous Cart to a User's Cart.
Version
v2
Arguments
This method has the path /cart/<version>/cart.create
and
follows the MicroBase API calling conventions.
Argument | Required | Type | Example | Description |
---|---|---|---|---|
customerId | no | String | A21afRq1 | The User identifier. Mandatory in the Cart, defaults to 'ANON'. |
anonymousCartId | no | String | 12qRE4EE | An anonymous cart to be merged with the new one. In this case the customerId is mandatory. |
previousCartId | no | String | RWc4egt6 | A Customer existent Cart where to merge the anonymousCartId to. In this case the anonymousCartId is mandatory. |
currency | no (*) | String | USD | ISO 4217 Currency to be asociated to the Cart. (*) Mandatory in the Cart, defaults to a config property. |
country | no | String | US | ISO 3166-1 alpha-2 Country to be asociated to the Cart. |
channel | no (*) | String | WEB | Distribution Channel to be asociated to the Cart. (*) Mandatory in the Cart, defaults to a config property. |
Response
Returns a Cart object:
{
"ok": true,
"cart": {
"id": "H19PRsec",
"customerId": "ANON",
"currency": "USD",
"channel": "WEB",
"expirationTime": "2016-08-23T15:16:50.407Z",
"items": []
}
}
Merge Cart
- If you provide an
anonymousCartId
, the system will assign that Cart to the providedcustomerId
. - If you provide a
previousCartId
along with theanonymousCartId
, the system will assign the anonymous Cart to the providedcustomerId
, and will deactivate (set the status toMERGED
) thepreviousCartId
. The previous Cart is suitable for being collected by the abandoned Cart process.
Errors
Expected errors that this method could return. Some errors return additional data.
Error | Data | Description |
---|---|---|
validation_error | The data causing the error | Some validation error |
invalid_country | The country code | The country code is invalid |
invalid_currency | The currency code | The currency code is not invalid |
invalid_customer | The customer id | The customer id is not valid |
missing_customer | - | If you provide an anonymousCartId , you must also provide a valid customerId |
missing_anonymous_cart_id | - | If you provide an previousCartId , you must also provide a valid anonymousCartId |
invalid_cart | The Cart id | The Cart id provided is invalid |
invalid_customer_cart | The previous Cart id | The previousCartId doesn't belong to the customerId provided. |
Example
curl --request POST \
--url http://localhost:3000/services/cart/v1/cart.create \
--header 'authorization: Bearer xxxxx...' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{}'