post https://{subdomain}.myshoplaza.com/openapi/2022-01/price_rules
Requires
price_rules
access scope. More access scope
The Create Price Rule API allows you to create a new price rule for discounts or promotions on the store.
This API is especially useful for:
- Managing discounts and promotional campaigns.
- Creating conditional offers based on cart total or product quantity.
- Automating discount rules for specific products or product variants.
Request Parameters
Public Request Parameters
Body Parameters
Field | Type | Required | Description | Example |
---|---|---|---|---|
title |
string |
Yes | Title of this price rule. | "Discount Rule Title" |
value |
double |
Yes | Value for this discount. | 50.25 |
value_type |
string |
Yes | Discount type. Options: fixed_amount for a fixed discount, or percentage for a percentage discount. |
"fixed_amount" |
usage_limit |
int32 |
No | The usage limit. -1 means no limit. |
-1 |
allocation_limit |
int32 |
No | Redeem count limit per checkout: 0 means only one redeem allowed, 999 means no limit. |
0 |
once_per_customer |
int32 |
No | Maximum usage per customer. -1 or 0 means no limit. |
1 |
prerequisite |
int32 |
No | Indicates if this discount has prerequisites. 1 means yes, 0 means no. |
1 |
target_selection |
string |
Yes | Target products allowed for this discount. Options: all for all products, entitled for specific products. |
"entitled" |
target_type |
string |
No | Target type of this discount. | "line_item" |
starts_at |
string |
Yes | Start time of the discount. | "2024-12-01T00:00:00Z" |
ends_at |
string |
Yes | End time of the discount. | "2024-12-31T23:59:59Z" |
entitled_product_ids |
array[string] |
No | Specifies the product IDs allowed for the price rule. Required only when target_selection is entitled . |
["ce21d85-a419-4d4e-a17d-5bddbc4ab7f6", "de2c55f5-3c81-45e1-9276-e65faf816ecc"] |
entitled_variant_ids |
array[string] |
No | Specifies the product variant IDs allowed for the price rule. | ["ce21d85-a419-4d4e-a17d-5bddbc4ab7f6"] |
prerequisite_subtotal_range |
array[object] |
No | Prerequisite for total amount in the cart. | [{"greater_than_or_equal_to":"100","value":"10"}] |
prerequisite_subtotal_range. |
string |
Yes | Specifies the minimum total cart amount required. | "100" |
prerequisite_subtotal_range. |
string |
Yes | Value used for discount application. | "10" |
prerequisite_subtotal_range. |
string |
No | Specifies the type of target the rule applies to. | "" |
prerequisite_subtotal_range. |
array[string] |
No | Specifies IDs of specific target items for the rule. | [] |
prerequisite_quantity_range |
array[object] |
No | Prerequisite for total quantity of products in the cart. | [{"greater_than_or_equal_to":"5","value":"20"}] |
prerequisite_quantity_range. |
string |
Yes | Specifies the minimum total product quantity required. | "5" |
prerequisite_quantity_range. |
string |
Yes | Value used for discount application. | "20" |
prerequisite_quantity_range. |
string |
No | Specifies the type of target the rule applies to. | "" |
prerequisite_quantity_range. |
array[string] |
No | Specifies IDs of specific target items for the rule. | [] |
Response Explanation
Public Response Parameters
Successful Response
Field | Type | Example | Description |
---|---|---|---|
price_rule |
object |
See fields below. | Object containing details about the created price rule. |
price_rule[] |
string |
"2d7e416a-444f-4491-ae04-c50f47154140" |
Unique identifier of the price rule. |
price_rule[] |
string |
"Buy 2 Get 1 Free" |
Title of this price rule. |
price_rule[] |
double |
10.5 |
Value of the discount. |
price_rule[] |
string |
"fixed_amount" |
Type of the discount value. Options: percentage , fixed_amount . |
price_rule[] |
string |
"100" |
Maximum number of times the discount can be used. -1 means no limit. |
price_rule[] |
string |
"5" |
Number of times the discount has been used. |
price_rule[] |
string |
"each" |
Allocation method for the discount. |
price_rule[] |
string |
"1" |
Redeem count limit per checkout. 0 means no limit. |
price_rule[] |
string |
"0" |
Indicates if the discount can be used only once per customer. "1" means yes. |
price_rule[] |
string |
"1" |
Indicates if the discount has prerequisites. "1" means yes. |
price_rule[] |
string |
"specific" |
Specifies the customer selection for the discount. |
price_rule[] |
string |
"entitled" |
Specifies the target product selection for the discount. |
price_rule[] |
string |
"line_item" |
Specifies the type of target for the discount. |
price_rule[] |
string |
"2024-12-19 10:00:00" |
Timestamp of when the price rule was created. |
price_rule[] |
string |
"2024-12-20 12:00:00" |
Timestamp of when the price rule was last updated. |
price_rule[] |
string |
"1700000000" |
Start time of the discount (Unix timestamp). |
price_rule[] |
string |
"1700500000" |
End time of the discount (Unix timestamp). |
price_rule[] |
array[string] |
["product-1", "product-2", "product-3"] |
List of product IDs entitled for the discount. |
price_rule[] |
array[string] |
["variant-1", "variant-2"] |
List of product variant IDs entitled for the discount. |
price_rule[] |
array[object] |
See fields below. | Prerequisite for total product quantity in the cart. |
price_rule[] |
string |
"3" |
Minimum quantity of products required to apply the discount. |
price_rule[] |
string |
"15" |
Value used for discount application. |
price_rule[] |
string |
"line_item" |
Specifies the type of target for the discount. |
price_rule[] |
array[string] |
["target-1", "target-2"] |
List of target data IDs for the discount rule. |
price_rule[] |
array[object] |
See fields below. | Prerequisite for total cart amount. |
price_rule[] |
string |
"100" |
Minimum subtotal amount required to apply the discount. |
price_rule[] |
string |
"20" |
Discount value applied when subtotal condition is met. |
price_rule[] |
string |
"line_item" |
Specifies the type of target for the discount. |
price_rule[] |
array[string] |
["subtotal-target-1"] |
List of target data IDs for the subtotal discount rule. |
Error Response
Error responses in the API can be represented using two different fields: errors
and error
. Both fields provide details about issues encountered during request processing. Below is an explanation of the fields with their respective examples and descriptions.
Field | Type | Example | Description |
---|---|---|---|
errors | Array | [ "invalid line_item id"] | A list of errors encountered during the request processing. |
Field | Type | Example | Description |
---|---|---|---|
error | String | "store is not active" | Indicates an error encountered during the process |
Error Detail
Status Code | Message | Possible Reason | Example Response |
---|---|---|---|
400 | Bad Request | Invalid input format or request structure (e.g., missing required fields or incorrect data types). | Bad Request |
Unauthorized | The request is missing valid authentication credentials or the credentials provided are invalid. | Unauthorized | |
422 | Title cannot be blank. | Empty title. | Title cannot be blank. |
Value Type is invalid. | The type value provided is invalid. | Value Type is invalid. | |
Value Type cannot be blank. | Empty value type | Value Type cannot be blank. | |
Target Selection is invalid. | The target selection provided is invalid. | Target Selection is invalid. | |
Target Type is invalid. | The target type provided is invalid. | Target Type is invalid. |