Create Custom Coupons

A number of use cases may require creating adaptive coupons using our Management API. This guide shows you how you can programmatically create coupons with attributes to configure their behaviour.

As an example, consider a campaign that rewards individual customers with a personal coupon code. Your campaign rules will contain some sort of "coupon belongs to the current user" logic, but the coupon itself needs to carry the information about which profile it belongs to.

#Coupon attributes

To establish this link, you can configure a BelongsToProfileId attribute on coupons themselves, and then define this attribute when creating coupons.

For example, in a Ruby application you might have something like so:

# profile_id: the same ID used in the integration API to identify this customer
# campaign: a campaign object previously retrieved from the Management API
def create_coupon_for_customer_and_campaign(profile_id, campaign)
  talon = TalonOne::Management::Client.new
  talon.post("/v1/applications/#{campaign["applicationId"]}/campaigns/#{campaign["id"]}/coupons", {
    "couponPattern"   => "My-Promo-####",
    "numberOfCoupons" => 1,  # How many coupons codes to create
    "usageLimit"      => 1,  # How many times each coupon can be used
    "attributes" => {
      "BelongsToProfileId" => profile_id
    }
  })
end

The above method will create a coupon with a random code that references a given customer. By adding a campaign rule that validates Coupon.Attributes.BelongsToProfileId = Profile.Id, only customer-specific coupons will be redeemed by the campaign.

References: