Skip to main content

Basket recalculate

It is possible that a user modifies the basket from OpenApp, for instance to change the quantity of a product or to add a discount coupon. OpenApp will validate that change at the website to make sure that it is applied corectly. This is visible as step 8 in the sequence diagram:

Request

In this case OpenApp will execute a HTTP POST to the to the endpoint configured in the control panel, with an updated basket in the request body:

POST <recalculate-url>

So if you configured the value https://shop.example.com/api/openapp/basket, the request executed by OpenApp will be:

POST https://shop.example.com/api/openapp/basket

The request body contains the basket from the user. For example:

{
"requestId": "request-id",
"id": "basket-id",
"price": {
"currency": "PLN",
"discounts": [
{
"code": "new-discount-code-text"
}
]
},
"products": [
{
"ean": "12312",
"id": "id123",
"quantity": 3
}
],
"loggedUser": "user-id-from-webshop"
}

Response

In reponse, the website should send the basket content and configured delivery options in the same format as for the retrieve basket response. Of course it is possible that the website can not accomodate the requested basket change, for instance because not enough stock is available. In that scenario the website should repond with the part of the basket that is available, plus an error code to indicate any errors in the basket. This is shown in the example below:

{
"id": "basket-id",
"expiresAt": "2022-03-23T21:00:00Z",
"price": {
"currency": "PLN",
"discounts": [
{
"code": "discount-code-text",
"value": 1000
}
],
"basketValue": 13000
},
"deliveryOptions": [
{
"key": "INPOST_APM",
"cost": 0
},
{
"key": "DPD_COURIER",
"cost": 1000,
"timing": "next business day"
}
],
"products": [
{
"ean": "12312",
"id": "id123",
"name": "Superb product",
"images": [
"http://cdn.merchant.com/static/products/id123/1",
"http://cdn.merchant.com/static/products/id123/2"
],
"quantity": 2,
"unitPrice": 7000,
"linePrice": 14000,
"originalUnitPrice": 7000,
"originalLinePrice": 14000,
"policies": [
{
"type": "AGE",
"criteria": {
"minAge": 18
}
}
]
}
],
"loggedUser": "user-id-from-webshop"
}

This example is an example of a simple basket. For a complete description of the basket response see the Schema tab above.