Discount Codes
With Discount Codes it is possible to give specific Cart Discounts to eligible customers. They are defined by a string value which can be added to a Cart so that specific Cart Discounts can be applied to the cart.
A DiscountCode can apply up to 10 CartDiscounts.
Representations
DiscountCode
idString | Unique identifier of the DiscountCode. |
versionInt | Current version of the DiscountCode. |
name | Name of the DiscountCode. |
description | Description of the DiscountCode. |
codeString | User-defined unique identifier of the DiscountCode added to the Cart to apply the related CartDiscounts. |
cartDiscountsArray of CartDiscountReference | Reference to CartDiscounts that can be applied to the Cart once the DiscountCode is applied. |
cartPredicateString | DiscountCode can only be applied to Carts that match this predicate. |
isActiveBoolean | Indicates if the DiscountCode is active and can be applied to the Cart. |
referencesArray of Reference | Array generated from the Cart predicate. It contains the references of all the resources that are addressed in the predicate. |
maxApplicationsInt | Number of times the DiscountCode can be applied. DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count. |
maxApplicationsPerCustomerInt | Number of times the DiscountCode can be applied per Customer (anonymous Carts are not supported). DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count. |
groupsArray of String | Groups to which the DiscountCode belongs to. |
validFrom | Date and time (UTC) from which the DiscountCode is effective. |
validUntil | Date and time (UTC) until which the DiscountCode is effective. |
applicationVersionInt | Used and managed by the API and must not be used in customer logic. The value can change at any time due to internal and external factors. |
custom | Custom Fields of the DiscountCode. |
createdAt | Date and time (UTC) the DiscountCode was initially created. |
createdByBETA | Present on resources created after 1 February 2019 except for events not tracked. |
lastModifiedAt | Date and time (UTC) the DiscountCode was last updated. |
lastModifiedByBETA | Present on resources created after 1 February 2019 except for events not tracked. |
DiscountCodeDraft
name | Name of the DiscountCode. |
description | Description of the DiscountCode. |
codeString | User-defined unique identifier for the DiscountCode that can be added to the Cart to apply the related CartDiscounts. It cannot be modified after the DiscountCode is created. |
cartDiscountsArray of CartDiscountResourceIdentifier | Specify what CartDiscounts the API applies when you add the DiscountCode to the Cart. MinItems:1MaxItems: 10 |
cartPredicateString | DiscountCode can only be applied to Carts that match this predicate. |
isActiveBoolean | Only active DiscountCodes can be applied to the Cart. Default:true |
maxApplicationsInt | Number of times the DiscountCode can be applied. |
maxApplicationsPerCustomerInt | Number of times the DiscountCode can be applied per Customer. |
groupsArray of String | Groups to which the DiscountCode will belong to. |
validFrom | Date and time (UTC) from which the DiscountCode is effective. Must be earlier than |
validUntil | Date and time (UTC) until which the DiscountCode is effective. Must be later than |
custom | Custom Fields for the DiscountCode. |
DiscountCodePagedQueryResponse
PagedQueryResult with results containing an array of DiscountCode.
limitInt | Number of results requested. |
offsetInt | Number of elements skipped. |
countInt | Actual number of results returned. |
totalInt | Total number of results matching the query.
This number is an estimation that is not strongly consistent.
This field is returned by default.
For improved performance, calculating this field can be deactivated by using the query parameter |
resultsArray of DiscountCode | DiscountCodes matching the query. |
DiscountCodeReference
Reference to a DiscountCode.
idString | Unique identifier of the referenced DiscountCode. |
typeIdString | "discount-code"References a DiscountCode. |
obj | Contains the representation of the expanded DiscountCode. Only present in responses to requests with Reference Expansion for DiscountCodes. |
DiscountCodeResourceIdentifier
idString | Unique identifier of the referenced DiscountCode. Either |
keyString | User-defined unique identifier of the referenced DiscountCode. Either |
typeIdString | "discount-code"References a DiscountCode. |
Get DiscountCode
Deprecated scope: view_orders:{projectKey}
view_discount_codes:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
expand | The parameter can be passed multiple times. |
200DiscountCode
curl -X GET https://api.{region}.commercetools.com/{projectKey}/discount-codes/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "3b3327a4-06c2-4129-8d87-83d5ce53e038","version" : 2,"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1","references" : [ ],"groups" : [ ],"createdAt" : "2015-09-15T09:02:29.323Z","lastModifiedAt" : "2015-09-15T09:04:06.910Z"}
Query DiscountCodes
Deprecated scope: view_orders:{projectKey}
view_discount_codes:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
where | The parameter can be passed multiple times. |
/^var[.][a-zA-Z0-9]+$/Any string parameter matching this regular expression | Predicate parameter values. The parameter can be passed multiple times. |
sort | The parameter can be passed multiple times. |
expand | The parameter can be passed multiple times. |
limitInt | Number of results requested. |
offsetInt | Number of elements skipped. |
withTotalBoolean | Controls the calculation of the total number of query results. Set to |
curl -X GET https://api.{region}.commercetools.com/{projectKey}/discount-codes -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"limit" : 20,"offset" : 0,"count" : 1,"total" : 1,"results" : [ {"id" : "3b3327a4-06c2-4129-8d87-83d5ce53e038","version" : 2,"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1","references" : [ ],"groups" : [ ],"attributeTypes" : { },"cartFieldTypes" : { },"lineItemFieldTypes" : { },"customLineItemFieldTypes" : { },"createdAt" : "2015-09-15T09:02:29.323Z","lastModifiedAt" : "2015-09-15T09:04:06.910Z"} ]}
Create DiscountCode
Deprecated scope: manage_orders:{projectKey}
manage_discount_codes:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
expand | The parameter can be passed multiple times. |
201DiscountCode
curl -X POST https://api.{region}.commercetools.com/{projectKey}/discount-codes -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1"}DATA
{"id" : "3b3327a4-06c2-4129-8d87-83d5ce53e038","version" : 2,"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1","references" : [ ],"groups" : [ ],"createdAt" : "2015-09-15T09:02:29.323Z","lastModifiedAt" : "2015-09-15T09:04:06.910Z"}
Update DiscountCode
Deprecated scope: manage_orders:{projectKey}
manage_discount_codes:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
expand | The parameter can be passed multiple times. |
versionInt | Expected version of the DiscountCode on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned. |
actionsArray of DiscountCodeUpdateAction | Update actions to be performed on the DiscountCode. |
200DiscountCode
curl -X POST https://api.{region}.commercetools.com/{projectKey}/discount-codes/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"version" : 1,"actions" : [ {"action" : "setName","name" : {"en" : "New Name"}} ]}DATA
{"id" : "3b3327a4-06c2-4129-8d87-83d5ce53e038","version" : 2,"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1","references" : [ ],"groups" : [ ],"createdAt" : "2015-09-15T09:02:29.323Z","lastModifiedAt" : "2015-09-15T09:04:06.910Z"}
Update actions
Set Name
actionString | "setName" |
name | Value to set. If empty, any existing value will be removed. |
{"action" : "setName","name" : {"en" : "New Name EN","de" : "New Name DE"}}
Set Description
actionString | "setDescription" |
description | Value to set. If empty, any existing value will be removed. |
{"action" : "setDescription","description" : {"en" : "New Description EN","de" : "New Description DE"}}
Set Cart Predicate
actionString | "setCartPredicate" |
cartPredicateString | Value to set. If empty, any existing value will be removed. |
{"action" : "setCartPredicate","cartPredicate" : "lineItemCount(sku = \"mySKU\") > 1"}
Set Max Applications
actionString | "setMaxApplications" |
maxApplicationsInt | Value to set. If empty, any existing value will be removed. |
{"action" : "setMaxApplications","maxApplications" : 100}
Set Max Applications Per Customer
actionString | "setMaxApplicationsPerCustomer" |
maxApplicationsPerCustomerInt | Value to set. If empty, any existing value will be removed. |
{"action" : "setMaxApplicationsPerCustomer","maxApplicationsPerCustomer" : 10}
Set Custom Type
actionString | "setCustomType" |
type | Defines the Type that extends the DiscountCode with Custom Fields. If absent, any existing Type and Custom Fields are removed from the DiscountCode. |
fields | Sets the Custom Fields fields for the DiscountCode. |
{"action" : "setCustomType","type" : {"id" : "{{type-id}}","typeId" : "type"},"fields" : {"examplaryStringTypeField" : "TextString"}}
Set CustomField
actionString | "setCustomField" |
nameString | Name of the Custom Field. |
value | If |
{"action" : "setCustomField","name" : "ExamplaryStringTypeField","value" : "TextString"}
Change CartDiscounts
actionString | "changeCartDiscounts" |
cartDiscountsArray of CartDiscountResourceIdentifier | New value to set. MinItems:1MaxItems: 10 |
{"action" : "changeCartDiscounts","cartDiscounts" : [ {"typeId" : "cart-discount","id" : "{{cartDiscountId}}"} ]}
Change Groups
actionString | "changeGroups" |
groupsArray of String | New value to set. An empty array removes the DiscountCode from all groups. |
{"action" : "changeGroups","groups" : [ "groupString" ]}
Change IsActive
actionString | "changeIsActive" |
isActiveBoolean | New value to set. Set to |
{"action" : "changeIsActive","isActive" : false}
Set Valid From
actionString | "setValidFrom" |
validFrom | Value to set that must be earlier than |
{"action" : "setValidFrom","validFrom" : "2018-10-12T14:00:00.000Z"}
Set Valid Until
actionString | "setValidUntil" |
validUntil | Value to set that must be later than |
{"action" : "setValidUntil","validFrom" : "2018-10-12T14:00:00.000Z"}
Set Valid From and Until
actionString | "setValidFromAndUntil" |
validFrom | Value to set that must be earlier than |
validUntil | Value to set that must be later than |
{"action" : "setValidFromAndUntil","validFrom" : "2018-10-12T14:00:00.000Z","validUntil" : "2018-10-12T14:05:00.000Z"}
Delete DiscountCode
The API does not check if a CartDiscount, Cart, or Order exists that has a reference to the DiscountCode before deleting it.
Deprecated scope: manage_orders:{projectKey}
manage_discount_codes:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
versionInt | Last seen version of the resource. |
expand | The parameter can be passed multiple times. |
dataErasureBoolean | Defaults to |
200DiscountCode
curl -X DELETE https://api.{region}.commercetools.com/{projectKey}/discount-codes/{id}?version={version} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
{"id" : "3b3327a4-06c2-4129-8d87-83d5ce53e038","version" : 2,"code" : "SAVE10","name" : {"en" : "Save10"},"cartDiscounts" : [ {"typeId" : "cart-discount","id" : "fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3"} ],"isActive" : true,"cartPredicate" : "1=1","references" : [ ],"groups" : [ ],"createdAt" : "2015-09-15T09:02:29.323Z","lastModifiedAt" : "2015-09-15T09:04:06.910Z"}