# Discounts

Manage Discounts

## Returning all discounts from the cart

> Returns all discounts of the specified cart.\
> \*\*\*\
> \
> \### Required scopes\
> \
> \*  \`cart.cart\_manage\`\
> \
> &#x20;   \*\*Note\*\*: This scope is only required for OAuth2 authorization method to authorize the request with the \`access\_token\`.

```json
{"openapi":"3.0.0","info":{"title":"Cart Service","version":"0.0.1"},"tags":[{"name":"Discounts","description":"Manage Discounts"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":[]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"https://api.emporix.io/oauth/token","scopes":{"cart.cart_manage":"Needed to manage carts."}}}}},"schemas":{"discountResponse":{"description":"Discount details.","type":"object","properties":{"id":{"type":"string","description":"Discount's unique identifier."},"yrn":{"$ref":"#/components/schemas/YRN"},"couponYrn":{"$ref":"#/components/schemas/YRN"},"code":{"maxLength":150,"description":"Discount code generated when a discount coupon is created through the Coupon Service.","type":"string"},"amount":{"type":"number","minimum":0,"description":"Discount expressed as fixed amount.","format":"double"},"currency":{"type":"string","pattern":"[A-Z]{3}","description":"Three-letter currency code, compliant with the ISO 4217 standard.","minLength":3,"maxLength":3},"discountRate":{"type":"number","minimum":0,"description":"Discount expressed as a percentage of the price.","format":"double"},"name":{"maxLength":150,"description":"Discount's displayed name.","type":"string"},"calculationType":{"type":"string","maxLength":30,"default":"ApplyDiscountBeforeTax","description":"Calculation type specifies how the discount should be calculated. Can be set to one of the following:\n* `ApplyDiscountBeforeTax`\n* `ApplyDiscountAfterTax`","enum":["ApplyDiscountBeforeTax","ApplyDiscountAfterTax"]},"discountCalculationType":{"type":"string","description":"Determines whether the coupon is applied to the total or subtotal value of the order.","enum":["SUBTOTAL","TOTAL"]},"valid":{"default":true,"description":"Flag indicating whether the discount is valid. \nInvalid discounts are not taken into account when the cart is calculated.","type":"boolean"},"links":{"minItems":2,"type":"array","description":"Links to Coupon Service endpoints used to validate and redeem the discount.","items":{"$ref":"#/components/schemas/link"}},"discountValidationDetails":{"$ref":"#/components/schemas/discountValidationDetails"},"discountIndex":{"type":"integer","description":"The index of the discount. It represents the discount position in the cart discounts array."}},"required":["code"]},"YRN":{"type":"string","title":"YRN","description":"A unique identifier of a global resource, which stores information about the resource, such as its type, ID or name of the tenant.","minLength":1},"link":{"description":"","type":"object","properties":{"rel":{"type":"string","maxLength":50,"description":"Action to be done using the endpoint provided in the `href` field.","enum":["validate","redeem"]},"title":{"maxLength":100,"description":"Detailed link description.","type":"string"},"href":{"type":"string","maxLength":2000,"description":"Endpoint used to validate or redeem the discount."},"type":{"type":"string","maxLength":500,"description":"Content type."}},"required":["rel","href","type"]},"discountValidationDetails":{"description":"","type":"object","properties":{"message":{"type":"string"},"details":{"type":"array","items":{"type":"string"}}}},"ErrorMessage":{"title":"error","description":"Schema for API-specific errors.","type":"object","properties":{"code":{"description":"Original HTTP error code. It should be consistent with the HTTP response code.","type":"integer"},"status":{"description":"HTTP Status","type":"string"},"message":{"description":"Descriptive error message for debugging purposes.","type":"string"}}}},"responses":{"trait_403":{"description":"Given authorization scopes are not sufficient and do not match scopes required by the endpoint.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_notFound_404":{"description":"The requested resource does not exist.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_500":{"description":"Some server-side error occurred. Details will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}}},"paths":{"/cart/{tenant}/carts/{cartId}/discounts":{"get":{"tags":["Discounts"],"summary":"Returning all discounts from the cart","operationId":"GET-cart-list-all-discounts","responses":{"200":{"description":"The request was successful. Cart discounts items are returned.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/discountResponse"}}}}},"403":{"$ref":"#/components/responses/trait_403"},"404":{"$ref":"#/components/responses/trait_notFound_404"},"500":{"$ref":"#/components/responses/trait_500"}},"description":"Returns all discounts of the specified cart.\n***\n\n### Required scopes\n\n*  `cart.cart_manage`\n\n    **Note**: This scope is only required for OAuth2 authorization method to authorize the request with the `access_token`."}}}}
```

## Applying a discount to cart

> Applies a discount on the specified cart. Multiple discount coupons can be applied to cart, but you need to send a separate request for each discount coupon.\
> \*\*\*\
> \
> \### Required scopes\
> \
> \*  \`cart.cart\_manage\`\
> \
> &#x20;   \*\*Note\*\*: This scope is only required for OAuth2 authorization method to authorize the request with the \`access\_token\`.

```json
{"openapi":"3.0.0","info":{"title":"Cart Service","version":"0.0.1"},"tags":[{"name":"Discounts","description":"Manage Discounts"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":[]},{"CustomerAccessToken":[]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"https://api.emporix.io/oauth/token","scopes":{"cart.cart_manage":"Needed to manage carts."}}}},"CustomerAccessToken":{"type":"http","scheme":"bearer"}},"schemas":{"appliedDiscount":{"type":"object","properties":{"yrn":{"$ref":"#/components/schemas/YRN"},"discountId":{"type":"string","format":"double"},"discountIndex":{"type":"integer","description":"The index of the discount that represents the number in the discounts array. It can be used for the discount removal from the cart."}},"required":["yrn","discountId","discountIndex"]},"YRN":{"type":"string","title":"YRN","description":"A unique identifier of a global resource, which stores information about the resource, such as its type, ID or name of the tenant.","minLength":1},"ErrorMessage":{"title":"error","description":"Schema for API-specific errors.","type":"object","properties":{"code":{"description":"Original HTTP error code. It should be consistent with the HTTP response code.","type":"integer"},"status":{"description":"HTTP Status","type":"string"},"message":{"description":"Descriptive error message for debugging purposes.","type":"string"}}},"discount":{"description":"","type":"object","title":"","properties":{"id":{"type":"string","description":"Discount unique identifier."},"couponYrn":{"$ref":"#/components/schemas/YRN"},"code":{"type":"string","maxLength":150,"description":"Discount code generated when a discount coupon is created through the Coupon Service.","minLength":1},"currency":{"type":"string","pattern":"[A-Z]{3}","description":"Three-letter currency code, compliant with the ISO 4217 standard.","minLength":3,"maxLength":3},"amount":{"type":"number","minimum":0,"description":"Discount expressed as fixed amount.","format":"double"},"name":{"maxLength":150,"description":"Discount displayed name.","type":"string"},"discountRate":{"type":"number","minimum":0,"description":"Discount expressed as a percentage of the price.","format":"double"},"discountCalculationType":{"type":"string","default":"SUBTOTAL","description":"Determines whether the coupon is applied to the total or subtotal value of the order.","enum":["SUBTOTAL","TOTAL"]},"links":{"minItems":2,"type":"array","description":"Links to Coupon Service endpoints used to validate and redeem the discount.","items":{"$ref":"#/components/schemas/link"}},"calculationType":{"type":"string","maxLength":30,"default":"ApplyDiscountBeforeTax","deprecated":true,"enum":["ApplyDiscountBeforeTax","ApplyDiscountAfterTax"],"description":"Calculation type specifies how the discount should be calculated. It can be set to one of the following:\n* `ApplyDiscountBeforeTax`\n* `ApplyDiscountAfterTax`\n\nThe field is **deprecated** and is not used in calculatedPrice fields. The calculated price takes into account site's settings\nwhere:\n* `includesTax=true` results in `ApplyDiscountAfterTax`\n* `includesTax=false` results in `ApplyDiscountBeforeTax`"}},"required":["code"]},"link":{"description":"","type":"object","properties":{"rel":{"type":"string","maxLength":50,"description":"Action to be done using the endpoint provided in the `href` field.","enum":["validate","redeem"]},"title":{"maxLength":100,"description":"Detailed link description.","type":"string"},"href":{"type":"string","maxLength":2000,"description":"Endpoint used to validate or redeem the discount."},"type":{"type":"string","maxLength":500,"description":"Content type."}},"required":["rel","href","type"]}},"responses":{"trait_400":{"description":"The request was syntactically incorrect. Details will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_401":{"description":"Given request is unauthorized - the authorization token is invalid or has expired.\n\nDetails will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_403":{"description":"Given authorization scopes are not sufficient and do not match scopes required by the endpoint.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_notFound_404":{"description":"The requested resource does not exist.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_add_discount_conflict_409":{"description":"The request could not be completed due to a conflict with the current state of the target resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"parameters":{"trait_tenant":{"name":"tenant","in":"path","required":true,"description":"Your Emporix tenant name.\n\n**Note**: The tenant should always be written in lowercase.\n","schema":{"pattern":"^[a-z][a-z0-9]+$","minLength":3,"maxLength":16,"type":"string"}}}},"paths":{"/cart/{tenant}/carts/{cartId}/discounts":{"post":{"tags":["Discounts"],"responses":{"201":{"description":"The request was successful. The discount has been applied to cart.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/appliedDiscount"}}},"headers":{"Location":{"description":"Location of the newly created discount.","schema":{"type":"string"}}}},"400":{"$ref":"#/components/responses/trait_400"},"401":{"$ref":"#/components/responses/trait_401"},"403":{"$ref":"#/components/responses/trait_403"},"404":{"$ref":"#/components/responses/trait_notFound_404"},"409":{"$ref":"#/components/responses/trait_add_discount_conflict_409"},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"description":"","type":"object","properties":{"code":{"type":"number","description":"Original HTTP error code. It should be consistent with the HTTP response code."},"status":{"type":"string","minLength":1,"description":"Classification of the error."},"message":{"type":"string","minLength":1,"description":"Descriptive error message for debugging purposes."}}}}}}},"description":"Applies a discount on the specified cart. Multiple discount coupons can be applied to cart, but you need to send a separate request for each discount coupon.\n***\n\n### Required scopes\n\n*  `cart.cart_manage`\n\n    **Note**: This scope is only required for OAuth2 authorization method to authorize the request with the `access_token`.","operationId":"POST-cart-apply-discount","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/discount"}}},"required":false},"parameters":[{"$ref":"#/components/parameters/trait_tenant"}],"summary":"Applying a discount to cart"}}}}
```

## Removing all discounts from cart

> Removes all discounts applied to the specified cart.\
> \*\*\*\
> \
> \### Required scopes\
> \
> \*  \`cart.cart\_manage\`\
> \
> &#x20;   \*\*Note\*\*: This scope is only required for OAuth2 authorization method to authorize the request with the \`access\_token\`.

```json
{"openapi":"3.0.0","info":{"title":"Cart Service","version":"0.0.1"},"tags":[{"name":"Discounts","description":"Manage Discounts"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":[]},{"CustomerAccessToken":[]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"https://api.emporix.io/oauth/token","scopes":{"cart.cart_manage":"Needed to manage carts."}}}},"CustomerAccessToken":{"type":"http","scheme":"bearer"}},"responses":{"trait_400":{"description":"The request was syntactically incorrect. Details will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_401":{"description":"Given request is unauthorized - the authorization token is invalid or has expired.\n\nDetails will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_403":{"description":"Given authorization scopes are not sufficient and do not match scopes required by the endpoint.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_notFound_404":{"description":"The requested resource does not exist.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_500":{"description":"Some server-side error occurred. Details will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"schemas":{"ErrorMessage":{"title":"error","description":"Schema for API-specific errors.","type":"object","properties":{"code":{"description":"Original HTTP error code. It should be consistent with the HTTP response code.","type":"integer"},"status":{"description":"HTTP Status","type":"string"},"message":{"description":"Descriptive error message for debugging purposes.","type":"string"}}}},"parameters":{"trait_tenant":{"name":"tenant","in":"path","required":true,"description":"Your Emporix tenant name.\n\n**Note**: The tenant should always be written in lowercase.\n","schema":{"pattern":"^[a-z][a-z0-9]+$","minLength":3,"maxLength":16,"type":"string"}}}},"paths":{"/cart/{tenant}/carts/{cartId}/discounts":{"delete":{"tags":["Discounts"],"responses":{"204":{"description":"The request was successful. Discounts have been removed."},"400":{"$ref":"#/components/responses/trait_400"},"401":{"$ref":"#/components/responses/trait_401"},"403":{"$ref":"#/components/responses/trait_403"},"404":{"$ref":"#/components/responses/trait_notFound_404"},"500":{"$ref":"#/components/responses/trait_500"}},"description":"Removes all discounts applied to the specified cart.\n***\n\n### Required scopes\n\n*  `cart.cart_manage`\n\n    **Note**: This scope is only required for OAuth2 authorization method to authorize the request with the `access_token`.","operationId":"DELETE-cart-remove-all-discounts","parameters":[{"$ref":"#/components/parameters/trait_tenant"},{"schema":{"type":"string"},"in":"query","name":"codes","description":"Discount codes, listed with commas, specify the discounts slated for deletion. If no codes are provided, all discounts will be removed."}],"summary":"Removing all discounts from cart"}}}}
```

## Removing a discount from cart

> Delete the discount in the cart by the provided discount Index.\
> \*\*\*\
> \
> \### Required scopes\
> \
> \*  \`cart.cart\_manage\`\
> \
> &#x20;   \*\*Note\*\*: This scope is only required for OAuth2 authorization method to authorize the request with the \`access\_token\`.

```json
{"openapi":"3.0.0","info":{"title":"Cart Service","version":"0.0.1"},"tags":[{"name":"Discounts","description":"Manage Discounts"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"OAuth2":[]},{"CustomerAccessToken":[]}],"components":{"securitySchemes":{"OAuth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"https://api.emporix.io/oauth/token","scopes":{"cart.cart_manage":"Needed to manage carts."}}}},"CustomerAccessToken":{"type":"http","scheme":"bearer"}},"responses":{"trait_400":{"description":"The request was syntactically incorrect. Details will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_401":{"description":"Given request is unauthorized - the authorization token is invalid or has expired.\n\nDetails will be provided in the response payload.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_403":{"description":"Given authorization scopes are not sufficient and do not match scopes required by the endpoint.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}},"trait_notFound_404":{"description":"The requested resource does not exist.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"schemas":{"ErrorMessage":{"title":"error","description":"Schema for API-specific errors.","type":"object","properties":{"code":{"description":"Original HTTP error code. It should be consistent with the HTTP response code.","type":"integer"},"status":{"description":"HTTP Status","type":"string"},"message":{"description":"Descriptive error message for debugging purposes.","type":"string"}}}},"parameters":{"trait_tenant":{"name":"tenant","in":"path","required":true,"description":"Your Emporix tenant name.\n\n**Note**: The tenant should always be written in lowercase.\n","schema":{"pattern":"^[a-z][a-z0-9]+$","minLength":3,"maxLength":16,"type":"string"}}}},"paths":{"/cart/{tenant}/carts/{cartId}/discounts/{discountIndex}":{"delete":{"tags":["Discounts"],"responses":{"204":{"description":"The request was successful. The discount has been removed from cart."},"400":{"$ref":"#/components/responses/trait_400"},"401":{"$ref":"#/components/responses/trait_401"},"403":{"$ref":"#/components/responses/trait_403"},"404":{"$ref":"#/components/responses/trait_notFound_404"},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"description":"Delete the discount in the cart by the provided discount Index.\n***\n\n### Required scopes\n\n*  `cart.cart_manage`\n\n    **Note**: This scope is only required for OAuth2 authorization method to authorize the request with the `access_token`.","operationId":"DELETE-cart-remove-discount","parameters":[{"$ref":"#/components/parameters/trait_tenant"}],"summary":"Removing a discount from cart"}}}}
```
