Importing Discount Codes

Create and update Discount Codes in your Project.

The Discount Codes data to import is represented by DiscountCodeImport and included in a DiscountCodeImportRequest, which is imported using Import Discount Codes.

Representations

DiscountCodeImportRequest

The request body to import Discount Codes. Contains data for Discount Codes to be created or updated in a Project.

"discount-code"

The Discount Code import resource type.

resources
Array of DiscountCodeImport

The Discount Code import resources of this request.

MaxItems: 20
Example: json
{
"type": "discount-code",
"resources": [
{
"key": "discountCodeKey",
"code": "Save10",
"name": {
"en": "Save10"
},
"cartDiscounts": [
{
"typeId": "cart-discount",
"key": "cartDiscountKey"
}
],
"isActive": false,
"groups": []
}
]
}

DiscountCodeImport

The data representation for a Discount Code to be imported that is persisted as a Discount Code in the Project.

key
String

User-defined unique identifier. If a Discount Code with this key exists, it will be updated with the imported data.

MinLength: 2MaxLength: 256Pattern: ^[A-Za-z0-9_-]+$
name

Maps to DiscountCode.name.

description

Maps to DiscountCode.description.

code
String

User-defined unique identifier of the DiscountCode that is used by the customer to apply the discount.

The value cannot be updated. Attempting to update the value will result in an InvalidFieldsUpdate error.

cartDiscounts

Reference to CartDiscounts that can be applied to the Cart once the DiscountCode is applied.

cartPredicate
String

DiscountCode can only be applied to Carts that match this predicate.

isActive
Boolean

Indicates if the DiscountCode is active and can be applied to the Cart.

maxApplications
Int

Number of times the DiscountCode can be applied. DiscountCode application is counted at the time of Order creation or update. However, Order cancellation or deletion does not decrement the count.

maxApplicationsPerCustomer
Int

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 update. However, Order cancellation or deletion does not decrement the count.

groups
Array of String

Groups to which the DiscountCode belongs.

validFrom

Date and time (UTC) from which the DiscountCode is effective.

validUntil

Date and time (UTC) until which the DiscountCode is effective.

custom

Custom Fields of the DiscountCode.

Import Discount Codes

POST
https://import.{region}.commercetools.com/{projectKey}/discount-codes/import-containers/{importContainerKey}

Creates a request for creating new Discount Codes or updating existing ones.

OAuth 2.0 Scopes:
manage_discount_codes:{projectKey}view_discount_codes:{projectKey}
Path parameters:
region
String

The Region in which the Project is hosted.

projectKey
String

The Project key.

importContainerKey
String

The ImportContainer used to create the new resource

Request Body:DiscountCodeImportRequestasapplication/json
Response:
201ImportResponseasapplication/json
Request Example:cURL
curl https://import.{region}.commercetools.com/{projectKey}/discount-codes/import-containers/{importContainerKey} -i \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header 'Content-Type: application/json' \
--data-binary @- << DATA
{
"type" : "discount-code",
"resources" : [ {
"key" : "discountCodeKey",
"code" : "Save10",
"name" : {
"en" : "Save10"
},
"cartDiscounts" : [ {
"typeId" : "cart-discount",
"key" : "cartDiscountKey"
} ],
"isActive" : false,
"groups" : [ ]
} ]
}
DATA