Discount API

For more details about this API usage check our API documentation

Introduction

The discount API allows to user managing of discounts. Discounts can be created, queried, modified or deleted. Additional properties can be adjusted using specific endpoints made for that purpose.

Preparation

  • Have an authenticated token from the authentication service, this token should be used as an authorization bearer token header for every request done in this API (more information about the authorization service here).

Create a discount

Discounts can be created by making a POST request to the /discounts endpoint. The details of the discount must be specified in the request body. An example request can be seen bellow.

Example request body:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 500,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
}
}

These are some important attributes to clarify about discounts, we are omitting the ones that are self-explanatory:

  • The name of a discount is a reference name meant to be displayed on a visual interface (i.e the cash register frontend application).
  • The type value can either be RELATIVE or ABSOLUTE, in this example we are dealing with a RELATIVE discount, it means it represents a percentage based discount, units are represented a 1/100th of one percent (500 is equivalent to 5,00%). Absolute discounts are based on a fixed currency amount, the units are represented in cents (500 represents 5,00€)
  • properties encloses a list of particular properties of the discount.
  • automatic flag determines if a discount is applied automatically for every product in a purchase.
  • manualRate flag establishes if a discount rate can be manually modified after being applied on a product.
  • employee flag tells if a discount is employee discount or not.
  • combinableWith is a list of discount Ids the discount in question can be combined with, a discount cannot be applied along other ones in the same product if they are not contained in this list.
  • validFromTime value represents the local time of the day since a discount can be applied on a product. The value is writen in military time format (500 represents 5 hours and 0 minutes in the morning).
  • validFromTime value represents the local time of the day until a discount can be applied on a product. The value is writen in military time format (2300 represents 23 hours and 0 minutes in the evening).
  • stores contains a list of store numbers the discount in question can be used on, the discount can be used only in the stores contained in this list.
  • distChains comprises a list of distribution chains the discount in question can be used on, the discount can be used only in the distribution chains contained in this list.

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 500,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04001",
"message": "Created successfully"
}
}

Get a discount

Discounts can be queried by making a GET request to the /discounts/{discountId} endpoint, no request body is required.

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 500,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04002",
"message": "Retrieved successfully"
}
}

Update a discount

To modify a discount a PATCH request need to be done to the /discounts/{discountId} endpoint. Almost every attribute can be modified. In the example bellow we'll update a discount rate.

Example request body:

{
"rate" : 1000
}

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Delete a discount

To delete a discount a DELETE request need to be done to the /discounts/{discountId} endpoint, no request body is required.

Example response:

{
"apiResponseStatus": {
"responseCode": "I04004",
"message": "Deleted successfully"
}
}

Set a discount to be able to be combined with others

To make a discount to be able be combined with others, a POST request need to be done to the /discounts/{discountId}/combinableWith endpoint. The discountId provided as path variable is the discount to which we are providing the new discounts can be combined with it. An example request can be seen bellow.

Example request body:

{
"combinableWith" : [
"d4",
"d5"
]
}

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4",
"d5"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Disable a discount to be combined with others

To remove a discount from the combinableWith discount list a DELETE request need to be done to the /discounts/{discountId}/combinableWith/{discountId} endpoint. The first discountId is the discount from which we will look into the combinableWith list, the second one is the specific discount to be removed from such list, no request body is required.

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Set the stores a discount is available to be used

To add stores a discount is available to be used on, a POST request need to be done to the /discounts/{discountId}/stores endpoint. The discountId given as path variable specifies the stores to which we are setting the discount to be available on. An example request can be seen bellow.

Example request body:

{
"stores": [
"9998",
"9997"
]
}

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999",
"9998",
"9997"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Remove a discount to be used in a specific store

To remove a discount from being used in a specific store we need to use a DELETE request to the /discounts/{discountId}/stores/{storeId} endpoint. The storeId given in the path variable is the one which will be removed from list of stores the discount is available to be used on, no request body is required. In this example we are removing discount d1 to be used in store 9997.

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999",
"9998"
],
"distChains": [
"DE01"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Set the distribution chains a discount can be used on

To add distribution chains a discount is available to be used on, a POST request need to be done to the /discounts/{discountId}/distchains endpoint. The discountId given as path variable specifies the distribution chain to which we are setting the discount to be available on. An example request can be seen bellow.

Example request body:

{
"distChains": [
"DE02",
"DE03"
]
}

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999",
"9998"
],
"distChains": [
"DE01",
"DE02",
"DE03"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}

Remove a discount to be used in a specific distribution chain

To remove a discount from being used in a specific distribution chain we need to use a DELETE request to the /discounts/{discountId}/distchains/{distchain} endpoint. The distchain given in the path variable is the specific distribution chain that will be removed from list of distribution chains the discount is available to be used on, no request body is required. In this example we are removing discount d1 to be used in distribution chain DE03.

Example response:

{
"discountId" : "d1",
"name" : "Example discount",
"rate" : 1000,
"type" : "RELATIVE",
"properties": {
"automatic": false,
"manualRate": false,
"employee": false,
"calculatedFromBasePrice": false,
"combinableWith": [
"d2",
"d3",
"d4"
]
},
"temporalValidity": {
"validFromDate": "2020-07-04",
"validUntilDate": "2099-12-31",
"validFromTime": 500,
"validUntilTime": 2300,
"dayOfWeekList": [
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
]
},
"locationValidity": {
"stores": [
"9999",
"9998"
],
"distChains": [
"DE01",
"DE02"
]
},
"apiResponseStatus": {
"responseCode": "I04003",
"message": "Updated successfully"
}
}