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)

Discount Code properties

id

"id": 1206854680

A unique identifier for the discount code.

created_at

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

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

updated_at

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

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

applies_once

"applies_once": false

true: Once per order.

false: For each item in the cart.

code

"code": "XPJR0FYULPGB"

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

ends_at

"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

"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

"minimum_order_amount" : 0 

Order value applies to promotion

usage_limit

"usage_limit": 1

The number of times that the discount code has been redeemed.

discount_type

"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

"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

"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

"is_promotion":false

Apply in conjunction with other promotions

times_used

"times_used":1

Number of times used

Endpoints

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

Retrieves a list of enabling discount codes.

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

View response

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": []
        },
        {
            "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": []
        }
    ]
}
				

Retrieves a list of enable discount codes by code.

GET https://apis.haravan.com/com/discounts.json?code=GARMIN55

View response

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": []
        }
    ]
}
				
GET https://apis.haravan.com/com/discounts/{discountId}.json

Retrieves single the discount code.

Retrieves single the discount code.

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

View response

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
    }
}

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
        ]
    }
}

View response

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
    }
}

Update status enable a discount code.

PUT https://apis.haravan.com/com/discounts/1017981791/enable.json

{}

View response

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
    }
}

Update status disables a discount code.

PUT https://apis.haravan.com/com/discounts/1017981791/disable.json

{}

View response

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
    }
}

Delete a discount code.

DELETE https://apis.haravan.com/com/discounts/1017981791.json

{}

View response

HTTP/1.1 200 OK
{}