Glue API: Manage discount vouchers in carts of registered users
Edit on GitHubThis endpoint allows managing discount vouchers in carts of registered users.
Installation
For detailed information on the modules that provide the API functionality and related installation instructions, see Install the Promotions & Discounts feature Glue API.
Apply a discount voucher to a cart of a registered user
To apply a discount voucher to a cart of a registered user, send the request:
POST
/carts/{{uuid}}/vouchers
PATH PARAMETER | DESCRIPTION |
---|---|
{{uuid}} | The unique ID of the cart to apply the discount voucher to. To get it, Create a cart or Retrieve a registered user’s carts. |
Request
HEADER KEY | HEADER TYPE | REQUIRED | DESCRIPTION |
---|---|---|---|
Authorization | String | ✓ | An alphanumeric string that authorizes the customer to send requests to protected resources. Get it by authenticating as a customer. |
QUERY PARAMETER | DESCRIPTION | POSSIBLE VALUES |
---|---|---|
Include | Adds resource relationships to the request. | vouchers |
Request sample: apply a discount voucher to a cart of a registered user
POST https://glue.mysprykershop.com/carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/vouchers
{
"data": {
"type": "vouchers",
"attributes": {
"code": "sprykerku2f"
}
}
}
Request sample: apply a discount voucher to a cart of a registered user with details on discount voucher information
POST https://glue.mysprykershop.com/carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/vouchers?include=vouchers
{
"data": {
"type": "vouchers",
"attributes": {
"code": "mydiscount-qa1ma"
}
}
}
ATTRIBUTE | TYPE | REQUIRED | DESCRIPTION |
---|---|---|---|
code | String | yes | The unique ID of a discount voucher to apply. |
Response
Response sample: apply a discount voucher to a cart of a registered user
{
"data": {
"type": "carts",
"id": "c9310692-2ab0-5edc-bb41-fee6aa828d55",
"attributes": {
"priceMode": "GROSS_MODE",
"currency": "EUR",
"store": "DE",
"totals": {
"expenseTotal": 0,
"discountTotal": 21831,
"taxTotal": 19752,
"subtotal": 145540,
"grandTotal": 123709,
"priceToPay": 123709
},
"discounts": [
{
"displayName": "5% discount on all white products",
"amount": 7277,
"code": null
}
],
"thresholds": []
},
"links": {
"self": "https://glue.mysprykershop.com/carts/c9310692-2ab0-5edc-bb41-fee6aa828d55"
}
}
}
Response sample: apply a discount voucher to a cart of a registered user with details on discount voucher information
{
"data": {
"type": "carts",
"id": "56a0b4e4-21d8-516f-acd5-90581c996676",
"attributes": {
"priceMode": "GROSS_MODE",
"currency": "EUR",
"store": "DE",
"name": "Shopping cart",
"isDefault": true,
"totals": {...},
"discounts": [
{
"displayName": "My Discount",
"amount": 83133,
"code": null
},
{
"displayName": "10% Discount for all orders above",
"amount": 33253,
"code": null
}
],
"thresholds": []
},
"links": {...},
"relationships": {
"vouchers": {
"data": [
{
"type": "vouchers",
"id": "mydiscount-qa1ma"
}
]
}
}
},
"included": [
{
"type": "vouchers",
"id": "mydiscount-qa1ma",
"attributes": {
"amount": 83133,
"code": "mydiscount-qa1ma",
"discountType": "voucher",
"displayName": "My Discount",
"isExclusive": false,
"expirationDateTime": "2020-02-29 00:00:00.000000",
"discountPromotionAbstractSku": null,
"discountPromotionQuantity": null
},
"links": {
"self": "https://glue.mysprykershop.com/vouchers/mydiscount-qa1ma?include=vouchers"
}
}
]
}
RESOURCE | ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|---|
vouchers, cart-rules | displayName | String | Discount name displayed on the Storefront. |
vouchers, cart-rules | amount | Integer | Amount of the provided discount. |
vouchers, cart-rules | code | String | Discount code. |
vouchers, cart-rules | discountType | String | Discount type. |
vouchers, cart-rules | isExclusive | Boolean | Discount exclusivity. |
vouchers, cart-rules | expirationDateTime | DateTimeUtc | Date and time on which the discount expires. |
vouchers, cart-rules | discountPromotionAbstractSku | String | SKU of the products to which the discount applies. If the discount can be applied to any product, the value is null . |
vouchers, cart-rules | discountPromotionQuantity | Integer | Specifies the amount of the product required to be able to apply the discount. If the minimum number is 0 , the value is null . |
Remove a discount voucher from a registered user’s cart
To remove a discount voucher, send the request:
DELETE
/carts/{{uuid}}/vouchers/{{voucher_id}}
PATH PARAMETER | DESCRIPTION |
---|---|
{{uuid}} | The unique ID of the registered user’s cart to remove the discount voucher from. To get it, Retrieve a registered user’s cart. |
{{voucher_id}} | The unique ID of the voucher to remove. To get it, Retrieve a registered user’s cart or Retrieve a registered user’s carts with the vouchers resource included. |
Request
HEADER KEY | HEADER TYPE | REQUIRED | DESCRIPTION |
---|---|---|---|
Authorization | String | ✓ | An alphanumeric string that authorizes the customer to send requests to protected resources. Get it by authenticating as a customer. |
Request sample: remove a discount voucher from a registered user’s cart
DELETE https://glue.mysprykershop.com/carts/1ce91011-8d60-59ef-9fe0-4493ef3628b2/vouchers/mydiscount-we3ca
Response
If the voucher is deleted successfully, the endpoints returns the 204 No Data
status code.
Possible errors
CODE | REASON |
---|---|
001 | Access token is incorrect. |
002 | Access token is missing. |
003 | Failed to log in the user. |
3301 | Cart or voucher with the specified ID is not found. |
3302 | Incorrect voucher code or the voucher cannot be applied. |
3303 | Cart code can’t be removed. |
To view generic errors that originate from the Glue Application, see Reference information: GlueApplication errors.
Thank you!
For submitting the form