Skip to main content

Add Discount Tutorial

How to add discount tutorial

This guide shows how to obtaining the discounts availability for the items added to the shopping cart and apply them easily.

Let's get started with the examples

Step-by-step examples

This guide shows how to obtaining and apply an discount step by step.

Prerequisites!

You will need a valid OAuth access_token to be able to make each call! Please refer to our Authentication Guide to obtain one.

Get Available Promotion and Discounts

This call returns the list of available promotions and discounts for the products in the shopping cart:

  • token Shopping cart identifier.
curl --location --request GET 'http://gateway-pre.oneboxtickets.net/onebox-rest2/rest/shoppingCart/availablePromotionsAndDiscounts?token={{cart-token}}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{access_token}}' \
--header 'Content-Type: application/json'

Note: This endpoint returns a list of items that contains the information related to it's availability of promotions and discounts, so in order to be able to do the next step, we must take the item-id ("@id": "173012531" in the example below) and the desired discount-id ( "@id": "122402" in the example below), you can see the list in more detail in this example:

EXAMPLE RESPONSE:

{
"@token": "c13749c8b3060f35ef5b40107ed5b96d",
"@currency": "EUR",
"@timeLeft": "544",
"shopping-cart-item-sales": {
"@id": "173012531",
"promotions": null,
"discounts": {
"discount": {
"@id": "122402",
"promotionComElements": {
"name": "33% Discount"
},
"type": "PERCENTAGE",
"value": "33.0",
"mandatory": "false",
"self-managed": "false",
"limitedUses": "false"
}
}
}
}

Apply Discount

Finally to apply the discount we make this call to the addDiscount endpoint passing it an XML structure that includes the discount-id, also send the item-id obtained in the previous step, and the cart-token of the shopping cart to which the discount is going to be applied:

  • discount-id Discount unique identifier.
  • cart-token Shopping cart identifier token.
  • item-id Item unique identifier.
curl --location --request POST 'http://gateway-pre.oneboxtickets.net/onebox-rest2/rest/shoppingCart/addDiscount' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {{access_token}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'discount=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3Cdiscount%20id%3D%22122402%22%20xmlns%3D%22http%3A%2F%2Fwww.oneboxtm.es%2Fns%2Finput-data%2Fshopping%2Fcart%22%2F%3E&items={{item-id}}&token={{cart-token}}'

Note: Although the integration is JSON, the discount XML structure that you send as parameter must be in this XML format since the API expects this structure and format when receive and processing the call. To make it more readable, the decoded structure is shown below:

Discount XML structure unencoded:

<?xml version="1.0" encoding="UTF-8"?><discount id="122402" xmlns="http://www.oneboxtm.es/ns/input-data/shopping/cart"/>