Skip to main content
POST
Create earning rule

Authorizations

X-App-Id
string
header
required
X-App-Token
string
header
required

Body

application/json

Request body schema for POST /v2/loyalties/earning-rules.

name
string
required

Earning rule name.

Required string length: 1 - 200
trigger
object
required

Event that triggers the earning rule. Depending on event, either custom_event or segment is required and the other trigger contexts must be null/absent.

earnings
object[]
required

Defines the earnings evaluated when the trigger fires. Required. At least one item.

Minimum array length: 1
error
Custom error message configuration · object | null

Default error returned when rule validation fails. On create, omit the field or set it to null to store no error. On update, omit the field or set it to null to keep the stored error. The response omits error when none is stored.

start_date
string<date-time> | null

Sets the date-time from which the rule is active. A calendar date (YYYY-MM-DD) is accepted and stored as midnight UTC. Set to null to clear the start. start_date must be earlier than end_date. On update, an omitted date keeps the stored value and is included in that comparison.

end_date
string<date-time> | null

Sets the date-time until which the rule is active. A calendar date (YYYY-MM-DD) is accepted and stored as midnight UTC. Set to null to clear the end. On update, an omitted date keeps the stored value.

metadata
object | null

Arbitrary key-value metadata. The response always returns an object. On create, omit the field or set it to null to store {}. On update, omit the field to keep stored keys, set null to clear them, or send an object to merge those keys into the stored object.

status
enum<string>

Initial status. Only DRAFT and ACTIVE are allowed at creation. Defaults to DRAFT.

Available options:
DRAFT,
ACTIVE
validity_hours
object | null

Hours during which the rule is active. Omit the field or set it to null to use { "type": "ANY_TIME" }. The response always returns validity_hours.

trigger_limits
object | null

Cooldown and frequency limits for the trigger. Omit the field or set it to null to use { "cooldown": { "type": "NO_COOLDOWN" }, "frequency": { "type": "NO_LIMIT" } }. The response always returns trigger_limits.

earning_limits
object | null

Limits how many points this rule can award. Omit the field or set it to null to use { "global": { "type": "NO_LIMIT", "limits": [] } }. The response always returns earning_limits.

Response

Earning rule created

Response body schema for POST /v2/loyalties/earning-rules.

id
string
required

Earning rule ID (lern_...).

Pattern: ^lern_[a-f0-9]+$
name
string
required

Earning rule name.

Maximum string length: 200
status
enum<string>
required

Current status. DELETED also exists internally but deleted rules are excluded from API reads.

Available options:
DRAFT,
ACTIVE,
INACTIVE
earnings
object[]
required

Earning definitions of the rule. Contains at least one earning.

Minimum array length: 1
trigger
object
required

Event that triggers the earning rule. Depending on event, either custom_event or segment is required and the other trigger contexts must be null/absent.

validity_hours
object
required

Validity hours. Always present; defaults to { "type": "ANY_TIME" }.

start_date
string<date-time> | null
required

Date-time from which the rule is active. Can be null.

end_date
string<date-time> | null
required

Date-time until which the rule is active. Can be null.

trigger_limits
object
required

Cooldown and frequency limits. Always present. cooldown and frequency are always objects. frequency.limits is always an array and is empty when frequency.type is NO_LIMIT.

earning_limits
object
required

Limits how many points this rule can award. Always present. Defaults to no global limit (global.type NO_LIMIT and global.limits []).

metadata
object
required

Arbitrary key-value metadata. Always present (empty object when unset).

created_at
string<date-time>
required

Creation timestamp (ISO 8601).

updated_at
string<date-time> | null
required

Last update timestamp (ISO 8601). null when never updated.

object
string
required

Object type marker. Always earning_rule.

Allowed value: "earning_rule"
error
Custom error message configuration · object

Default error configuration. Absent when not configured.