Skip to main content

DiscountCode

Version: 2.0

You can use the Discount Code resource to create discount codes that enable specific discounts to be redeemed. Merchants can distribute discount codes to their customers using a variety of means, such as an email or URL, and customers can apply these codes at checkout.

Authenticated access scopes: com.read_discounts, com.write_discounts (Only used by the private app)

What you can do with Discount Code

The Haravan API lets you do the following with the Discount Code resource.

Properties


id : number

"id": 1206854680

A unique identifier for the discount code.


created_at : string

"created_at": "2021-05-13T07:29:20.1Z"

The date and time (ISO 8601 format) when the discount code was created.


updated_at : string

"updated_at": "2021-05-13T07:29:20.808Z"

The date and time (ISO 8601 format) when the discount code was last updated.


applies_once : boolean

"applies_once": false
  • true : Discount can only be applied once on the entire order.

  • false : Promotion will apply to each item in the shopping cart.


code : string

"code": "XPJR0FYULPGB"

The case-insensitive discount code that customers use at checkout. (maximum: 200 characters)


ends_at : string

"ends_at": "2021-05-13T07:29:20.1Z"

Expiration date.The date and time (ISO 8601 format).

  • ends_at = null : Never expires.

  • ends_at != null: Must be greater than current date.


starts_at : string

"starts_at":"2021-05-13T07:29:20.1Z"

Promotion start date. The date and time (ISO 8601 format) must be greater than the current date.


minimum_order_amount : number

"minimum_order_amount" : 0

Minimum purchase value (Applies to all products).


usage_limit : number

"usage_limit": 1

Limit the total number of times the promotion can be used.


discount_type : string

"discount_type": "fixed_amount"
  • fixed_amount: Applies a discount of value as a unit of the store's currency.

  • percentage: Applies a percentage discount of value.

  • shipping: Free shipping.


applies_to_resource : string

"applies_to_resource":"product"
  • null: Apply to all orders.

  • product: Apply to the product.

  • province: Apply to province.

  • collection: Apply to the collection.

  • customer: Apply to customer.

  • group_customer: Apply to customer groups.

  • product_variant: Apply to product variants.


value : number

"value ": 150000

Discount value. If discount_type is "shipping". The value will be the shipping fee. It must be limited to how much shipping charges apply.


is_promotion : boolean

"is_promotion":false

Apply in conjunction with other promotions.


times_used : number

"times_used":1

Number of times used.


once_per_customer : false

"once_per_customer" : false
  • true
  • false

Applicable products

products_selection : string

"products_selection" : "all"
  • all : All
  • collection_prerequisite : Prerequisite collection
  • variant_prerequisite : Prerequisite variant
  • product_prerequisite : Prerequisite product

Applicable customer

customers_selection : string

"customers_selection" : "all"
  • all : All
  • customersegment_prerequisite : Prerequisite customer segment
  • customer_prerequisite : Prerequisite customer

Applicable shipping location

provinces_selection : string

"provinces_selection" : "all"
  • all: All
  • province_prerequisite: Prerequisite province

Applicable channels

channels_selection : string

"channels_selection" : "all"
  • all: All
  • channel_prerequisite: Prerequisite channel

Applicable locations

locations_selection : string

"locations_selection" : "all"
  • all: All
  • location_prerequisite Prerequisite location

Applicable collections

entitled_collection_ids : array

"entitled_collection_ids" : [1004145086, 1004145085, 1004145084]
  • entitled_collection_ids: Entitled collection

Applicable products

entitled_product_ids : array

"entitled_product_ids" : [1055262740, 1055262741, 1055262730]
  • entitled_product_ids: Entitled product ids

Applicable variants

entitled_variant_ids : array

"entitled_variant_ids" : [1124400234, 1124400235, 1124400233]
  • entitled_variant_ids: Entitled variant ids

Applicable customers

entitled_customer_ids : array

"entitled_customer_ids" : [1128891111]
  • entitled_customer_ids: Entitled customer ids

Customer eligibility

entitled_customer_segment_ids : array

"entitled_customer_segment_ids" : [73624622, 73624623, 73624624]
  • entitled_customer_segment_ids: Entitled custoemr segment ids

Applicable shipping location

entitled_province_ids : array

"entitled_province_ids" : [50, 32, 57]
  • entitled_province_ids: Entitled province ids

Applicable channels

entitled_channels : array

"entitled_channels" : ["pos", "web", "harasocial"]
  • entitled_channels: Entitled channels

Applicable locations

entitled_location_ids : array

"entitled_location_ids" : [1690961]
  • entitled_location_ids: Entitled location ids

Rule customs

rule_customs : array

"rule_customs" : [
{
"name": "customer_limit_used",
"value": "5"
},
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]},{\"name\":\"wednesday\",\"value_range\":[[\"1:00\",\"1:30\"]]},{\"name\":\"thursday\",\"value_range\":[]}]"
},
{
"name": "shipping_max_apply_value",
"value": "100"
}
]
  • customer_limit_used: Limit to one use per customer
  • time_range: Active dates
  • shipping_max_apply_value: Shipping max

Discount type

take_type : string

"take_type" : "fixed_amount"
  • fixed_amount : Fixed amount
  • percentage : Percentage

Retrieves a list of enabling discount codes

GET
https://apis.haravan.com/com/discounts.json

Retrieves a list of enabling discount codes.

Parameters


limit

Limit of the result.


page

Page to show the result.


since_id

Restrict results to after the specified ID.


code

Filter result by the code.


Retrieves a list of enabling discount codes by page number. By default, the number of resources on the page is 50.

  • GET https://apis.haravan.com/com/discounts.json?page=1
Details
HTTP/1.1 200 OK
{
"discounts": [
{
"applies_once": false,
"applies_to_id": 39550382,
"code": "TEST GROUP",
"ends_at": null,
"id": 1017981560,
"minimum_order_amount": 0.0,
"starts_at": "2021-07-28T10:12:00Z",
"status": "enabled",
"usage_limit": 1,
"value": 10.0000,
"discount_type": "percentage",
"times_used": 0,
"is_promotion": true,
"applies_to_resource": "group_customer",
"variants": [],
"location_ids": [],
"create_user": 200000493247,
"first_name": "Trọng",
"last_name": "Nhân Lê",
"applies_customer_group_id": null,
"created_at": "2021-07-28T10:13:35.639Z",
"updated_at": "2021-07-28T10:13:35.643Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": [],
"once_per_customer": false,
"products_selection": "product_prerequisite",
"customers_selection": "all",
"provinces_selection": "all",
"channels_selection": "all",
"locations_selection": "all",
"entitled_collection_ids": [],
"entitled_product_ids": [
1055262740,
1055262730,
1055262741
],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [],
"entitled_province_ids": [],
"entitled_channels": [],
"entitled_location_ids": [],
"rule_customs": [
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]}]"
}
],
"take_type": "fixed_amount"
},
{
"applies_once": false,
"applies_to_id": null,
"code": "EQWEQWEQWEQWEQWEWEWEQEQWEQWEQWEQWEQWEQWEQWE",
"ends_at": null,
"id": 1017969576,
"minimum_order_amount": 0.0,
"starts_at": "2021-07-27T05:49:00Z",
"status": "enabled",
"usage_limit": 1,
"value": 10.0000,
"discount_type": "fixed_amount",
"times_used": 0,
"is_promotion": true,
"applies_to_resource": null,
"variants": [],
"location_ids": [],
"create_user": 200000493247,
"first_name": "Trọng",
"last_name": "Nhân Lê",
"applies_customer_group_id": null,
"created_at": "2021-07-27T05:49:28.333Z",
"updated_at": "2021-07-27T05:49:28.333Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": [],
"once_per_customer": false,
"products_selection": "product_prerequisite",
"customers_selection": "all",
"provinces_selection": "province_prerequisite",
"channels_selection": "channel_prerequisite",
"locations_selection": "location_prerequisite",
"entitled_collection_ids": [],
"entitled_product_ids": [
1055262718,
1055262665,
1055262732
],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [
73624621,
73624622,
73624623,
73624624
],
"entitled_province_ids": [
1,
57
],
"entitled_channels": [
"harasocial"
],
"entitled_location_ids": [
1690961
],
"rule_customs": [
{
"name": "customer_limit_used",
"value": "10"
}
],
"take_type": "fixed_amount"
}
]
}

Retrieves a list of enable discount codes by code.

  • GET https://apis.haravan.com/com/discounts.json?code=GARMIN55
Details
HTTP/1.1 200 OK
{
"discounts": [
{
"applies_once": false,
"applies_to_id": null,
"code": "GARMIN55",
"ends_at": null,
"id": 1016875801,
"minimum_order_amount": 0.0,
"starts_at": "2021-06-22T04:16:00Z",
"status": "enabled",
"usage_limit": null,
"value": 5.0000,
"discount_type": "percentage",
"times_used": 1,
"is_promotion": true,
"applies_to_resource": null,
"variants": [],
"location_ids": [],
"create_user": 200000493247,
"first_name": "Trọng",
"last_name": "Nhân Lê",
"applies_customer_group_id": 39550382,
"created_at": "2021-06-22T04:17:56.847Z",
"updated_at": "2021-06-22T04:17:56.847Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": [],
"once_per_customer": false,
"products_selection": "all",
"customers_selection": "all",
"provinces_selection": "province_prerequisite",
"channels_selection": "channel_prerequisite",
"locations_selection": "location_prerequisite",
"entitled_collection_ids": [],
"entitled_product_ids": [],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [
73624622,
73624623,
73624624
],
"entitled_province_ids": [
50,
32,
57
],
"entitled_channels": [
"pos",
"web",
"harasocial"
],
"entitled_location_ids": [
1690961
],
"rule_customs": [
{
"name": "customer_limit_used",
"value": "5"
},
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]},{\"name\":\"wednesday\",\"value_range\":[[\"1:00\",\"1:30\"]]},{\"name\":\"thursday\",\"value_range\":[]}]"
}
],
"take_type": "fixed_amount"
}
]
}

Retrieves single the discount code

GET
https://apis.haravan.com/com/discounts/{discountId}.json

Retrieves single the discount code.

  • GET https://apis.haravan.com/com/discounts/1016875801.json
Details
HTTP/1.1 200 OK
{

"discount": {
"applies_once": false,
"applies_to_id": null,
"code": "GARMIN55",
"ends_at": null,
"id": 1016875801,
"minimum_order_amount": 0.0,
"starts_at": "2021-06-22T04:16:00Z",
"status": "enabled",
"usage_limit": 0,
"value": 5.0000,
"discount_type": "percentage",
"times_used": 1,
"is_promotion": true,
"applies_to_resource": null,
"variants": null,
"location_ids": null,
"create_user": 200000493247,
"first_name": "Trọng",
"last_name": "Nhân Lê",
"applies_customer_group_id": 39550382,
"created_at": "2021-06-22T04:17:56.847Z",
"updated_at": "2021-06-22T04:17:56.847Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": null,
"once_per_customer": false,
"products_selection": "all",
"customers_selection": "all",
"provinces_selection": "all",
"channels_selection": "all",
"locations_selection": "all",
"entitled_collection_ids": [],
"entitled_product_ids": [],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [],
"entitled_province_ids": [],
"entitled_channels": [],
"entitled_location_ids": [],
"rule_customs": [
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]},{\"name\":\"wednesday\",\"value_range\":[]}]"
}
],
"take_type": "fixed_amount"
}
}

Create a discount code

POST
https://apis.haravan.com/com/discounts.json

Create a discount code.
  • POST https://apis.haravan.com/com/discounts.json
{
"discount": {
"is_promotion": true,
"applies_to_resource": null,
"applies_to_id": null,
"applies_once": false,
"code": "SUMMER_28/07",
"ends_at": null,
"minimum_order_amount": 0,
"starts_at": "2021-07-28T10:53:00Z",
"usage_limit": 10,
"value": 100000,
"discount_type": "fixed_amount",
"variants": [
{
"product_id": 1028183633,
"variant_id": 1061514625
},
{
"product_id": 1028183633,
"variant_id": 1061514629
}
],
"set_time_active": true,
"applies_customer_group_id": "39550400",
"location_ids": [1007284]
}
}
Details
HTTP/1.1 200 OK
{
"discount": {
"applies_once": false,
"applies_to_id": null,
"code": "GARMIN55",
"ends_at": null,
"id": 1016875801,
"minimum_order_amount": 0.0,
"starts_at": "2021-06-22T04:16:00Z",
"status": "enabled",
"usage_limit": 0,
"value": 5.0000,
"discount_type": "percentage",
"times_used": 1,
"is_promotion": true,
"applies_to_resource": null,
"variants": null,
"location_ids": null,
"create_user": 200000493247,
"first_name": "Trọng",
"last_name": "Nhân Lê",
"applies_customer_group_id": 39550382,
"created_at": "2021-06-22T04:17:56.847Z",
"updated_at": "2021-06-22T04:17:56.847Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": null,
"once_per_customer": false,
"products_selection": "all",
"customers_selection": "all",
"provinces_selection": "all",
"channels_selection": "all",
"locations_selection": "location_prerequisite",
"entitled_collection_ids": [],
"entitled_product_ids": [],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [],
"entitled_province_ids": [],
"entitled_channels": [],
"entitled_location_ids": [
1007284
],
"rule_customs": [],
"take_type": "fixed_amount"

}
}

Update status enables a discount code

PUT
https://apis.haravan.com/com/discounts/{discountId}/enable.json

Update status enable a discount code.

  • PUT https://apis.haravan.com/com/discounts/1017981791/enable.json
{}
Details
HTTP/1.1 200 OK
{
"discount": {
"applies_once": false,
"applies_to_id": null,
"code": "SUMMER_28/07",
"ends_at": null,
"id": 1017981791,
"minimum_order_amount": 0.0,
"starts_at": "2021-07-28T03:53:00Z",
"status": "disabled",
"usage_limit": 10,
"value": 100000.0000,
"discount_type": "fixed_amount",
"times_used": 0,
"is_promotion": true,
"applies_to_resource": null,
"variants": null,
"location_ids": [
1007284
],
"create_user": 200000497867,
"first_name": null,
"last_name": null,
"applies_customer_group_id": 39550400,
"created_at": "2021-07-28T11:27:34.029Z",
"updated_at": "2021-07-28T11:34:45.9148559Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": null,
"once_per_customer": false,
"products_selection": "all",
"customers_selection": "all",
"provinces_selection": "all",
"channels_selection": "all",
"locations_selection": "all",
"entitled_collection_ids": [],
"entitled_product_ids": [],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [],
"entitled_province_ids": [],
"entitled_channels": [],
"entitled_location_ids": [],
"rule_customs": [
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]},{\"name\":\"wednesday\",\"value_range\":[]}]"
}
],
"take_type": "fixed_amount"
}
}

Update status disables a discount code

PUT
https://apis.haravan.com/com/discounts/{discountId}/disable.json

Update status disables a discount code.

  • PUT https://apis.haravan.com/com/discounts/1017981791/disable.json
{}
Details
HTTP/1.1 200 OK
{
"discount": {
"applies_once": false,
"applies_to_id": null,
"code": "SUMMER_28/07",
"ends_at": null,
"id": 1017981791,
"minimum_order_amount": 0.0,
"starts_at": "2021-07-28T03:53:00Z",
"status": "disabled",
"usage_limit": 10,
"value": 100000.0000,
"discount_type": "fixed_amount",
"times_used": 0,
"is_promotion": true,
"applies_to_resource": null,
"variants": null,
"location_ids": [
1007284
],
"create_user": 200000497867,
"first_name": null,
"last_name": null,
"applies_customer_group_id": 39550400,
"created_at": "2021-07-28T11:27:34.029Z",
"updated_at": "2021-07-28T11:34:45.9148559Z",
"promotion_apply_type": 0,
"applies_to_quantity": 0,
"order_over": null,
"is_new_coupon": false,
"channel": null,
"max_amount_apply": null,
"is_advance_same_price_discount": false,
"advance_same_prices": null,
"once_per_customer": false,
"products_selection": "all",
"customers_selection": "all",
"provinces_selection": "all",
"channels_selection": "all",
"locations_selection": "all",
"entitled_collection_ids": [],
"entitled_product_ids": [],
"entitled_variant_ids": [],
"entitled_customer_ids": [],
"entitled_customer_segment_ids": [],
"entitled_province_ids": [],
"entitled_channels": [],
"entitled_location_ids": [],
"rule_customs": [
{
"name": "time_range",
"value": "[{\"name\":\"monday\",\"value_range\":[]},{\"name\":\"tuesday\",\"value_range\":[]},{\"name\":\"wednesday\",\"value_range\":[]}]"
}
],
"take_type": "fixed_amount"
}
}

Delete a discount code

DELETE
https://apis.haravan.com/com/discounts/{discountId}.json

Delete a discount code.

  • DELETE https://apis.haravan.com/com/discounts/1017981791.json
{}
Details
HTTP/1.1 200 OK
{}