Skip to main content
PUT
/
v1
/
loyalties
/
{campaignId}
/
earning-rules
/
{earningRuleId}
Update Earning Rule
curl --request PUT \
  --url https://{cluster}.voucherify.io/v1/loyalties/{campaignId}/earning-rules/{earningRuleId} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'X-App-Id: <api-key>' \
  --header 'X-App-Token: <api-key>' \
  --data '{
  "validation_rule_id": "val_7SxpdhPeBngA",
  "loyalty": {
    "type": "FIXED",
    "points": "5"
  },
  "source": {
    "banner": "Order paid 5 points."
  },
  "active": true,
  "start_date": "2022-11-02T13:00:00.000Z",
  "expiration_date": "2023-03-03T14:30:00.000Z",
  "validity_timeframe": {
    "duration": "PT1H",
    "interval": "P1D"
  },
  "validity_day_of_week": [
    0,
    1,
    2,
    3,
    4,
    5
  ],
  "metadata": {
    "Type": "Order paid - fixed amount of points"
  }
}'
{
  "id": "ern_63g6NQgtepfXn2z0QbT2ksLf",
  "created_at": "2022-11-29T11:10:46.523Z",
  "updated_at": "2022-11-29T11:30:57.652Z",
  "validation_rule_id": "val_7SxpdhPeBngA",
  "loyalty": {
    "points": 5,
    "type": "FIXED"
  },
  "event": "order.paid",
  "source": {
    "banner": "Order paid 5 points.",
    "object_id": "camp_fkZ28pe7DUAEmmabofkxHI8N",
    "object_type": "campaign"
  },
  "active": true,
  "start_date": "2022-11-02T13:00:00.000Z",
  "expiration_date": "2023-03-03T14:30:00.000Z",
  "validity_timeframe": {
    "duration": "PT1H",
    "interval": "P1D"
  },
  "validity_day_of_week": [
    0,
    1,
    2,
    3,
    4,
    5
  ],
  "object": "earning_rule",
  "automation_id": "auto_knM56LS3oygL0Ue0oeSNt4WA",
  "metadata": {
    "Type": "Order paid - fixed amount of points"
  }
}

Authorizations

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

The access token received from the authorization server in the OAuth 2.0 flow.

Path Parameters

campaignId
string
required

The campaign ID or name of the loyalty campaign. You can either pass the campaign ID, which was assigned by Voucherify, or the name of the campaign as the path parameter value, e.g., Loyalty%20Campaign.

Example:

"camp_rRsfatlwN7unSeUIJDCYedal"

earningRuleId
string
required

A unique earning rule ID.

Example:

"ern_CFuv1O0IDl8Jgph0ojhMu8bH"

Body

application/json

Specify the parameters that you would like to update for the given earning rule.

validation_rule_id
string

A unique validation rule identifier assigned by the Voucherify API. The validation rule is verified before points are added to the balance.

Example:

"val_248vs7tUjlIE"

loyalty
object

An object that defines the number of points that will be added to a loyalty card and how the points will be added.

  • FIXED adds a fixed number of points
  • PROPORTIONAL adds points proportionally based on a pre-defined ratio
  • Define fixed amount of points
  • Order Amount
  • Order Total Amount
  • Order Metadata
  • Order Items Quantity
  • Order Items Amount
  • Order Items Subtotal Amount
  • Define amount of points proportional to customer metadata
  • Earning Rule Proportional Custom Event
source
object

Contains the custom earning rule name and parent campaign.

active
boolean

A flag to toggle the earning rule on or off. You can disable an earning rule even though it's within the active period defined by the start_date and expiration_date of the campaign or the earning rule's own start_date and expiration_date.

  • true indicates an active earning rule
  • false indicates an inactive earning rule
start_date
string<date-time>

Start date defines when the earning rule starts to be active. Activation timestamp is presented in the ISO 8601 format. Earning rule is inactive before this date. If you don't define the start date for an earning rule, it will inherit the campaign start date by default.

Example:

"2022-02-02T13:00:00.000Z"

expiration_date
string<date-time>

Expiration date defines when the earning rule expires. Expiration timestamp is presented in the ISO 8601 format. Earning rule is inactive after this date.If you don't define the expiration date for an earning rule, it will inherit the campaign expiration date by default.

Example:

"2022-03-03T14:30:00.000Z"

pending_points
object | null

Defines the configuration for pending points. Pending points can be used only with the order.paid event. Pass null to remove pending points from the earning rule.

expiration_rules
object

Defines the loyalty point expiration rule. This expiration rule applies only to this earning rule and supersedes expiration_rules defined in the voucher.loyalty_card object.

validity_timeframe
object

Set recurrent time periods when the earning rule is valid. For example, valid for 1 hour every other day.start_date required when including the validity_timeframe.

validity_day_of_week
enum<integer>[]

Integer array corresponding to the particular days of the week in which the voucher is valid.

  • 0 Sunday
  • 1 Monday
  • 2 Tuesday
  • 3 Wednesday
  • 4 Thursday
  • 5 Friday
  • 6 Saturday
validity_hours
object

Determines the hours of validity, e.g. to create a happy hours scenario.

metadata
object

The metadata object stores all custom attributes assigned to the earning rule. A set of key/value pairs that you can attach to an earning rule object. It can be useful for storing additional information about the earning rule in a structured format.

Response

200 - application/json

Returns the updated earning rule object.

Response body schema for PUT v1/loyalties/{campaignId}/earning-rules/{earningRuleId}.

id
string
required

Assigned by the Voucherify API, identifies the earning rule object.

created_at
string<date-time>
required

Timestamp representing the date and time when the earning rule was created. The value is shown in the ISO 8601 format.

loyalty
object
required
  • Define fixed amount of points
  • Order Amount
  • Order Total Amount
  • Order Metadata
  • Order Items Quantity
  • Order Items Amount
  • Order Items Subtotal Amount
  • Define amount of points proportional to customer metadata
  • Earning Rule Proportional Custom Event
source
object
required

Contains the custom earning rule name and parent campaign.

object
enum<string>
default:earning_rule
required

The type of the object represented by JSON. Default is earning_rule.

Available options:
earning_rule
automation_id
string
required

For internal use by Voucherify.

metadata
object
required

The metadata object stores all custom attributes assigned to the earning rule. A set of key/value pairs that you can attach to an earning rule object. It can be useful for storing additional information about the earning rule in a structured format.

validation_rule_id
string | null
required

A unique validation rule identifier assigned by the Voucherify API. The validation rule is verified before points are added to the balance.

updated_at
string<date-time> | null
required

Timestamp representing the date and time when the earning rule was last updated in ISO 8601 format.

active
boolean
required

A flag to toggle the earning rule on or off. You can disable an earning rule even though it's within the active period defined by the start_date and expiration_date of the campaign or the earning rule's own start_date and expiration_date.

  • true indicates an active earning rule
  • false indicates an inactive earning rule
event
string

Defines the event which triggers the earning rule to add points to a loyalty card.

Example:

"order.paid,customer.segment.entered,customer.loyalty.tier.upgraded,customer.loyalty.tier.downgraded,customer.loyalty.tier.prolonged,customer.loyalty.tier.joined,customer.loyalty.tier.left"

custom_event
object

Contains details about the custom event.

segment
object

Contains the ID of a customer segment. Required for the customer.segment.entered option in the event.

loyalty_tier
object

Defines the tier associated with the earning rule definition.

pending_points
object

Defines the configuration for pending points. Pending points can be used only with the order.paid event.

start_date
string

Start date defines when the earning rule starts to be active. Activation timestamp is presented in the ISO 8601 format. The earning rule is inactive before this date. If you do not define the start date for an earning rule, it will inherit the campaign start date by default.

expiration_date
string

Expiration date defines when the earning rule expires. Expiration timestamp is presented in the ISO 8601 format. The earning rule is inactive after this date. If you do not define the expiration date for an earning rule, it will inherit the campaign expiration date by default.

validity_timeframe
object

Set recurrent time periods when the earning rule is valid. For example, valid for 1 hour every other day.start_date required when including the validity_timeframe.

validity_day_of_week
enum<integer>[]

Integer array corresponding to the particular days of the week in which the voucher is valid.

  • 0 Sunday
  • 1 Monday
  • 2 Tuesday
  • 3 Wednesday
  • 4 Thursday
  • 5 Friday
  • 6 Saturday
validity_hours
object

Determines the hours of validity, e.g. to create a happy hours scenario.

expiration_rules
object

Defines the loyalty point expiration rule. This expiration rule applies only to this earning rule and supersedes expiration_rules defined in the voucher.loyalty_card object.

I