Create Price Rule

🔒

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:

  1. Managing discounts and promotional campaigns.
  2. Creating conditional offers based on cart total or product quantity.
  3. Automating discount rules for specific products or product variants.

Request Parameters

Public Request Parameters

📘

Public Request Parameters

Body Parameters

FieldTypeRequiredDescriptionExample
titlestringYesTitle of this price rule."Discount Rule Title"
valuedoubleYesValue for this discount.50.25
value_typestringYesDiscount type. Options: fixed_amount for a fixed discount, or percentage for a percentage discount."fixed_amount"
usage_limitint32NoThe usage limit. -1 means no limit.-1
allocation_limitint32NoRedeem count limit per checkout: 0 means only one redeem allowed, 999 means no limit.0
once_per_customerint32NoMaximum usage per customer. -1 or 0 means no limit.1
prerequisiteint32NoIndicates if this discount has prerequisites. 1 means yes, 0 means no.1
target_selectionstringYesTarget products allowed for this discount. Options: all for all products, entitled for specific products."entitled"
target_typestringNoTarget type of this discount."line_item"
starts_atstringYesStart time of the discount."2024-12-01T00:00:00Z"
ends_atstringYesEnd time of the discount."2024-12-31T23:59:59Z"
entitled_product_idsarray[string]NoSpecifies 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_idsarray[string]NoSpecifies the product variant IDs allowed for the price rule.["ce21d85-a419-4d4e-a17d-5bddbc4ab7f6"]
prerequisite_subtotal_rangearray[object]NoPrerequisite for total amount in the cart.[{"greater_than_or_equal_to":"100","value":"10"}]
prerequisite_subtotal_range.greater_than_or_equal_tostringYesSpecifies the minimum total cart amount required."100"
prerequisite_subtotal_range.valuestringYesValue used for discount application."10"
prerequisite_subtotal_range.target_typestringNoSpecifies the type of target the rule applies to.""
prerequisite_subtotal_range.target_dataarray[string]NoSpecifies IDs of specific target items for the rule.[]
prerequisite_quantity_rangearray[object]NoPrerequisite for total quantity of products in the cart.[{"greater_than_or_equal_to":"5","value":"20"}]
prerequisite_quantity_range.greater_than_or_equal_tostringYesSpecifies the minimum total product quantity required."5"
prerequisite_quantity_range.valuestringYesValue used for discount application."20"
prerequisite_quantity_range.target_typestringNoSpecifies the type of target the rule applies to.""
prerequisite_quantity_range.target_dataarray[string]NoSpecifies IDs of specific target items for the rule.[]

Response Explanation

Public Response Parameters

📘

Public Response Parameters

Successful Response

FieldTypeDescriptionExample
price_ruleobjectObject containing details about the created price rule.See fields below.
price_rule.idstringUnique identifier of the price rule."2d7e416a-444f-4491-ae04-c50f47154140"
price_rule.titlestringTitle of this price rule."Buy 2 Get 1 Free"
price_rule.valuedoubleValue of the discount.10.5
price_rule.value_typestringType of the discount value. Options: percentage, fixed_amount."fixed_amount"
price_rule.usage_limitstringMaximum number of times the discount can be used. -1 means no limit."100"
price_rule.times_usedstringNumber of times the discount has been used."5"
price_rule.allocation_methodstringAllocation method for the discount."each"
price_rule.allocation_limitstringRedeem count limit per checkout. 0 means no limit."1"
price_rule.once_per_customerstringIndicates if the discount can be used only once per customer. "1" means yes."0"
price_rule.prerequisitestringIndicates if the discount has prerequisites. "1" means yes."1"
price_rule.customer_selectionstringSpecifies the customer selection for the discount."specific"
price_rule.target_selectionstringSpecifies the target product selection for the discount."entitled"
price_rule.target_typestringSpecifies the type of target for the discount."line_item"
price_rule.created_atstringTimestamp of when the price rule was created."2024-12-19 10:00:00"
price_rule.updated_atstringTimestamp of when the price rule was last updated."2024-12-20 12:00:00"
price_rule.starts_atstringStart time of the discount (Unix timestamp)."1700000000"
price_rule.ends_atstringEnd time of the discount (Unix timestamp)."1700500000"
price_rule.entitled_product_idsarray[string]List of product IDs entitled for the discount.["product-1", "product-2", "product-3"]
price_rule.entitled_variant_idsarray[string]List of product variant IDs entitled for the discount.["variant-1", "variant-2"]
price_rule.prerequisite_quantity_rangearray[object]Prerequisite for total product quantity in the cart.See fields below.
price_rule.prerequisite_quantity_range.greater_than_or_equal_tostringMinimum quantity of products required to apply the discount."3"
price_rule.prerequisite_quantity_range.valuestringValue used for discount application."15"
price_rule.prerequisite_quantity_range.target_typestringSpecifies the type of target for the discount."line_item"
price_rule.prerequisite_quantity_range.target_dataarray[string]List of target data IDs for the discount rule.["target-1", "target-2"]
price_rule.prerequisite_subtotal_rangearray[object]Prerequisite for total cart amount.See fields below.
price_rule.prerequisite_subtotal_range.greater_than_or_equal_tostringMinimum subtotal amount required to apply the discount."100"
price_rule.prerequisite_subtotal_range.valuestringDiscount value applied when subtotal condition is met."20"
price_rule.prerequisite_subtotal_range.target_typestringSpecifies the type of target for the discount."line_item"
price_rule.prerequisite_subtotal_range.target_dataarray[string]List of target data IDs for the subtotal discount rule.["subtotal-target-1"]

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.

FieldTypeExampleDescription
errorsArray[ "invalid line_item id"]A list of errors encountered during the request processing.
FieldTypeExampleDescription
errorString "store is not active"Indicates an error encountered during the process

Error Detail

Status CodeMessagePossible ReasonExample Response
400Bad RequestInvalid input format or request structure (e.g., missing required fields or incorrect data types).Bad Request
UnauthorizedThe request is missing valid authentication credentials or the credentials provided are invalid.Unauthorized
422Title 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 typeValue 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.

API Structure Overview

Language
Credentials
Header
URL
Click Try It! to start a request and see the response here!