Create a promotion
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/promotions';const options = { method: 'POST', headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'}, body: '{"name":"20% off t-shirts","mode":"DISCOUNT_CODE","code":"SALE20","description":"20% off every t-shirt","start_at":"2024-01-01T00:00:00Z","end_at":"2024-12-31T23:59:59Z","type":"PRODUCT_DISCOUNT","condition_type":"PRODUCT","target_ids":["1","2","3"],"min_amount":100000,"min_quantity":2,"discount_method":"PERCENTAGE","discount_value":20,"max_discount_amount":100000,"fixed_price":50000,"gift_product_ids":["10","11"],"gift_quantity":1,"usage_limit":100,"usage_limit_per_user":1,"checkout_suggestion_enabled":false}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://apibase.ecomweb.app/api/v1/stores/example/promotions \ --header 'Content-Type: application/json' \ --header 'x-api-key: <x-api-key>' \ --data '{ "name": "20% off t-shirts", "mode": "DISCOUNT_CODE", "code": "SALE20", "description": "20% off every t-shirt", "start_at": "2024-01-01T00:00:00Z", "end_at": "2024-12-31T23:59:59Z", "type": "PRODUCT_DISCOUNT", "condition_type": "PRODUCT", "target_ids": [ "1", "2", "3" ], "min_amount": 100000, "min_quantity": 2, "discount_method": "PERCENTAGE", "discount_value": 20, "max_discount_amount": 100000, "fixed_price": 50000, "gift_product_ids": [ "10", "11" ], "gift_quantity": 1, "usage_limit": 100, "usage_limit_per_user": 1, "checkout_suggestion_enabled": false }'Creates a discount code or an automatic promotion. The promotion is ACTIVE as soon as it is created, whatever the dates, and its terms cannot be changed afterwards; to change them, disable it and create a new one. A discount code must not already belong to another active promotion, otherwise the call fails with 409 PROMOTION_CODE_EXISTS. When condition_type is PRODUCT, every ID in target_ids must be a product of the store.
Required scopes: write:promotions
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
Promotion name.
Example
20% off t-shirtsDISCOUNT_CODE when shoppers enter a code, AUTOMATIC when the promotion applies on its own.
Example
DISCOUNT_CODEDiscount code. Set it when mode is DISCOUNT_CODE; shoppers cannot redeem the promotion without one. It is stored upper-case and matched without regard to case, and must not already belong to an active promotion.
Example
SALE20Description.
Example
20% off every t-shirtWhen the promotion starts, as an ISO 8601 timestamp.
Example
2024-01-01T00:00:00ZWhen the promotion ends, as an ISO 8601 timestamp. Omit for no end date.
Example
2024-12-31T23:59:59ZWhat the promotion does: PRODUCT_DISCOUNT, CART_DISCOUNT, FREE_SHIPPING, FIXED_PRICE or GIFT.
Example
PRODUCT_DISCOUNTWhat target_ids refers to: PRODUCT, VARIANT or NONE.
Example
PRODUCTIDs of the products or variants the promotion applies to, as strings. Required, with at least one ID, unless condition_type is NONE.
Example
[ "1", "2", "3"]Minimum order amount the promotion needs.
Example
100000Minimum number of items the promotion needs.
Example
2PERCENTAGE or FIXED_AMOUNT.
Example
PERCENTAGEThe discount: a percentage or an amount, depending on discount_method.
Example
20Cap on the discount for a percentage promotion.
Example
100000Fixed price for a FIXED_PRICE promotion.
Example
50000IDs of the gift products, as strings. Used by GIFT promotions.
Example
[ "10", "11"]Quantity of gift given.
Example
1Total number of times the promotion can be used. Omit for unlimited.
Example
100Number of times one customer can use the promotion. Omit for unlimited.
Example
1Bật/tắt hiển thị khuyến mãi trong danh sách gợi ý ở trang checkout
Example
falseResponses
Section titled “Responses”object
DISCOUNT_CODE when shoppers enter a code, AUTOMATIC when it applies on its own.
The discount code, stored upper-case. Null for an automatic promotion.
Description, or null.
When the promotion ends, as an ISO 8601 timestamp. Null when it has no end date.
DRAFT, ACTIVE, EXPIRED or DISABLED. A new promotion is ACTIVE.
What the promotion does: PRODUCT_DISCOUNT, CART_DISCOUNT, FREE_SHIPPING, FIXED_PRICE or GIFT.
What target_ids refers to: PRODUCT, VARIANT or NONE.
IDs of the products or variants the promotion applies to, as strings. Empty when condition_type is NONE.
Minimum order amount the promotion needs. Null when there is none.
Minimum number of items the promotion needs. Null when there is none.
PERCENTAGE or FIXED_AMOUNT. Null for promotions without a discount value.
The discount: a percentage or an amount, depending on discount_method. Null when not set.
Cap on the discount for a percentage promotion. Null when there is none.
Fixed price for a FIXED_PRICE promotion. Null for other types.
IDs of the gift products, as strings. Empty unless the type is GIFT.
Quantity of gift given. Null for other types.
Total number of times the promotion can be used. Null means unlimited.
Number of times one customer can use the promotion. Null means unlimited.
Whether the promotion is suggested to shoppers at checkout.
When the promotion was deleted. Always null on promotions you can read.
ID of the user who created the promotion, or null.
ID of the user who last updated the promotion, or null.
Promotion ID.
Promotion name.
When the promotion starts, as an ISO 8601 timestamp.
When the promotion was created, as an ISO 8601 timestamp.
When the promotion was last updated, as an ISO 8601 timestamp.
Example
{ "mode": "DISCOUNT_CODE", "status": "DRAFT", "type": "PRODUCT_DISCOUNT", "condition_type": "PRODUCT", "discount_method": "PERCENTAGE"}The request is malformed or failed validation.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The request conflicts with the resource’s current state.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}