Skip to main content

Create a Cart Percent Discount with Custom Attribute

POST Create a Cart Percent with Custom Attribute

https://useast.api.elasticpath.com/v2/rule-promotions

Parameters

Headers

NameRequiredTypeDescription
AuthorizationRequiredstringThe Bearer token required to get access to the API.

Body

For descriptions about the other fields, refer to Promotions Builder API overview.

NameRequiredTypeDescription
rule_set.rules.strategyRequiredstringSpecifies the strategy for the rule. The supported strategy is cart_custom_attribute.
`rule_set.rules.operatorRequiredstringSpecifies the operators used for the rule strategy. The supported operators are in and nin.
rule_set.rules.argsRequiredstringRepresents the condition value associated with each rule within the rule set. It requires at least three arguments.
  • The first argument is the custom attribute key, a string of alphanumeric characters, underscores, or hyphens with a length between 1 to 255 characters. For example, member_status. See Request Example
  • The second argument is the custom attribute type, with one of the following values:
    • string
    • boolean
    • integer
    • float
  • The third argument is the values of the expected type based on the second argument. For example, based on the member_status and custom attribute type, the values could be gold, silver, and platinum.

Note that the maximum number of objects in the args array is 24.

Request Example

curl -X POST https://useast.api.elasticpath.com/v2/rule-promotions \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $ {
"data": {
"type": "rule_promotion",
"name": "$5 off cart with custom attribute",
"description": "$5 off cart with custom attribute",
"enabled": true,
"automatic": true,
"start": "2024-01-01",
"end": "2024-01-26",
"rule_set": {
"rules": {
"strategy": "cart_custom_attribute",
"operator": "in",
"args": [
"member_status",
"string",
"gold",
"platinum"
]
},
"actions": [
{
"strategy": "cart_discount",
"args": [
"percent",
500
]
}
]
}
}
}

Response Example

201 Created

{
"data": {
"type": "rule_promotion",
"id": "e42ec2df-5682-4047-bc22-9e5eb932ca4a",
"store_id": "85ea6cac-589a-4141-80d0-42b91aae73a7",
"name": "$5 off cart with custom attribute",
"description": "$5 off cart with custom attribute",
"enabled": true,
"automatic": true,
"rule_set": {
"catalog_ids": null,
"currencies": null,
"rules": {
"strategy": "cart_custom_attribute",
"operator": "in",
"args": [
"member_status",
"string",
"gold",
"platinum"
]
},
"actions": [
{
"strategy": "cart_discount",
"args": [
"percent",
500
]
}
]
},
"start": "2024-01-01T00:00:00Z",
"end": "2024-01-26T00:00:00Z",
"meta": {
"timestamps": {
"created_at": "2024-01-24T21:27:13.1Z",
"updated_at": "2024-01-24T21:27:13.1Z"
}
}
}
}