A valid request URL is required to generate request examples{
"id": "<string>",
"name": "<string>",
"earnings": [
{
"id": "<string>",
"name": "<string>",
"rules": {
"logic": "<string>"
},
"tier_rules": {
"any_of": [
{
"tier_structure_id": "<string>",
"tier_ids": [
"<string>"
]
}
]
},
"effects": [
{
"points": {
"value": 4503599627370495,
"card_definition_id": "<string>",
"points_expiration": {
"rolling_expiration": {
"period": {
"value": 2
},
"rounding": {
"value": 6
}
},
"calendar_expiration": {
"expiration_dates": [
{
"day": 16,
"month": 6
}
]
},
"sliding_expiration": {
"period": {
"value": 2
},
"earning_activity": true,
"spending_activity": true,
"custom_activity": true,
"custom_activity_types": [
"<string>"
]
}
}
},
"points_proportional": {
"card_definition_id": "<string>",
"points_expiration": {
"rolling_expiration": {
"period": {
"value": 2
},
"rounding": {
"value": 6
}
},
"calendar_expiration": {
"expiration_dates": [
{
"day": 16,
"month": 6
}
]
},
"sliding_expiration": {
"period": {
"value": 2
},
"earning_activity": true,
"spending_activity": true,
"custom_activity": true,
"custom_activity_types": [
"<string>"
]
}
},
"order": {
"amount": {
"every": 4503599627370496,
"value": 4503599627370495.5
},
"total_amount": {
"every": 4503599627370496,
"value": 4503599627370495.5
},
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"customer": {
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"custom_event": {
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"order_items": {
"amount": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
},
"subtotal_amount": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
},
"quantity": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
}
}
},
"benefit": {
"id": "<string>"
}
}
]
}
],
"trigger": {
"custom_event": {
"schema_id": "<string>"
},
"segment": {
"id": "<string>"
}
},
"error": {
"message": "<string>"
},
"validity_hours": {
"daily": [
{
"days_of_week": [
3
],
"start_time": "<string>",
"end_time": "<string>"
}
]
},
"start_date": "2023-11-07T05:31:56Z",
"end_date": "2023-11-07T05:31:56Z",
"trigger_limits": {
"cooldown": {
"fixed_cooldown": {
"period": {
"value": 2
}
}
},
"frequency": {
"limits": [
{
"type": "TIME_BASED",
"period": {
"type": "CURRENT_PERIOD",
"current_period": {}
},
"triggers": {
"max": 2
}
}
]
}
},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"object": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}Create earning rule
⚠️ BETA endpoint
This is a work-in-progress documentation of a BETA endpoint. The parameters, fields, request and response bodies, and other data may subject to change. If you want to share feedback or improvements, contact Voucherify support or your Technical Account Manager.
Creates a new earning rule. When status is omitted the rule is created as DRAFT.
When validity_hours is omitted it defaults to { "type": "ANY_TIME" }.
When trigger_limits is omitted it defaults to
{ "cooldown": { "type": "NO_COOLDOWN" }, "frequency": { "type": "NO_LIMIT" } }.
curl --request POST \
--url {protocol}://{host}/v2/loyalties/earning-rules \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-App-Id: <api-key>' \
--header 'X-App-Token: <api-key>' \
--data '
{
"name": "<string>",
"trigger": {
"custom_event": {
"schema_id": "<string>"
},
"segment": {
"id": "<string>"
}
},
"earnings": [
{
"effects": [
{}
],
"rules": {
"logic": "<string>"
},
"name": "<string>",
"tier_rules": {
"any_of": [
{
"tier_structure_id": "<string>",
"tier_ids": [
"<string>"
]
}
]
}
}
],
"error": {
"message": "<string>"
},
"validity_hours": {
"daily": [
{
"days_of_week": [
3
],
"start_time": "<string>",
"end_time": "<string>"
}
]
},
"start_date": "2023-11-07T05:31:56Z",
"end_date": "2023-11-07T05:31:56Z",
"metadata": {},
"trigger_limits": {
"cooldown": {
"fixed_cooldown": {
"period": {
"value": 2
}
}
},
"frequency": {
"limits": [
{
"type": "TIME_BASED",
"period": {
"type": "CURRENT_PERIOD",
"current_period": {}
},
"triggers": {
"max": 2
}
}
]
}
}
}
'{
"id": "<string>",
"name": "<string>",
"earnings": [
{
"id": "<string>",
"name": "<string>",
"rules": {
"logic": "<string>"
},
"tier_rules": {
"any_of": [
{
"tier_structure_id": "<string>",
"tier_ids": [
"<string>"
]
}
]
},
"effects": [
{
"points": {
"value": 4503599627370495,
"card_definition_id": "<string>",
"points_expiration": {
"rolling_expiration": {
"period": {
"value": 2
},
"rounding": {
"value": 6
}
},
"calendar_expiration": {
"expiration_dates": [
{
"day": 16,
"month": 6
}
]
},
"sliding_expiration": {
"period": {
"value": 2
},
"earning_activity": true,
"spending_activity": true,
"custom_activity": true,
"custom_activity_types": [
"<string>"
]
}
}
},
"points_proportional": {
"card_definition_id": "<string>",
"points_expiration": {
"rolling_expiration": {
"period": {
"value": 2
},
"rounding": {
"value": 6
}
},
"calendar_expiration": {
"expiration_dates": [
{
"day": 16,
"month": 6
}
]
},
"sliding_expiration": {
"period": {
"value": 2
},
"earning_activity": true,
"spending_activity": true,
"custom_activity": true,
"custom_activity_types": [
"<string>"
]
}
},
"order": {
"amount": {
"every": 4503599627370496,
"value": 4503599627370495.5
},
"total_amount": {
"every": 4503599627370496,
"value": 4503599627370495.5
},
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"customer": {
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"custom_event": {
"metadata": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"property": "<string>"
}
},
"order_items": {
"amount": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
},
"subtotal_amount": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
},
"quantity": {
"every": 4503599627370496,
"value": 4503599627370495.5,
"applicable_to": [
{
"product": {
"id": "<string>"
},
"sku": {
"id": "<string>"
},
"products_collection": {
"id": "<string>"
}
}
]
}
}
},
"benefit": {
"id": "<string>"
}
}
]
}
],
"trigger": {
"custom_event": {
"schema_id": "<string>"
},
"segment": {
"id": "<string>"
}
},
"error": {
"message": "<string>"
},
"validity_hours": {
"daily": [
{
"days_of_week": [
3
],
"start_time": "<string>",
"end_time": "<string>"
}
]
},
"start_date": "2023-11-07T05:31:56Z",
"end_date": "2023-11-07T05:31:56Z",
"trigger_limits": {
"cooldown": {
"fixed_cooldown": {
"period": {
"value": 2
}
}
},
"frequency": {
"limits": [
{
"type": "TIME_BASED",
"period": {
"type": "CURRENT_PERIOD",
"current_period": {}
},
"triggers": {
"max": 2
}
}
]
}
},
"metadata": {},
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"object": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}{
"code": 123,
"key": "<string>",
"message": "<string>",
"details": "<string>",
"request_id": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Request body for creating an earning rule.
Earning rule name.
1 - 200Event that triggers the earning rule. Depending on event, either custom_event or segment is required and the other trigger contexts must be null/absent.
Show child attributes
Show child attributes
Earning definitions (rules and effects) evaluated when the trigger fires.
1Show child attributes
Show child attributes
Initial status. Only DRAFT and ACTIVE are allowed at creation. Defaults to DRAFT.
DRAFT, ACTIVE Default error returned when rule validation fails. Nullable.
Show child attributes
Show child attributes
Hours during which the rule is active. Defaults to { "type": "ANY_TIME" } when omitted. Nullable.
Show child attributes
Show child attributes
Date-time from which the rule is active. Nullable.
Date-time until which the rule is active. Nullable.
Arbitrary key-value metadata. Nullable.
Cooldown and frequency limits for the trigger. Defaults to { "cooldown": { "type": "NO_COOLDOWN" }, "frequency": { "type": "NO_LIMIT" } } when omitted. Nullable.
Show child attributes
Show child attributes
Response
Earning rule created
Earning rule as returned by the API.
Earning rule ID (lern_...).
^lern_[a-f0-9]+$Earning rule name.
200Current status. DELETED also exists internally but deleted rules are excluded from API reads.
DRAFT, ACTIVE, INACTIVE Earning definitions of the rule.
Show child attributes
Show child attributes
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.
Show child attributes
Show child attributes
Default error configuration. Absent when not configured.
Show child attributes
Show child attributes
Validity hours. Always present; defaults to { "type": "ANY_TIME" }.
Show child attributes
Show child attributes
Date-time from which the rule is active. Nullable.
Date-time until which the rule is active. Nullable.
Cooldown and frequency limits. In responses, frequency.limits is always an array (empty for NO_LIMIT).
Show child attributes
Show child attributes
Arbitrary key-value metadata. Always present (empty object when unset).
Creation timestamp (ISO 8601).
Last update timestamp (ISO 8601). Null when never updated.
Object type marker. Always earning_rule.
"earning_rule"Was this page helpful?

