11th Jan 2021

Creating Custom Coupons

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

For example, consider a campaign that rewards individual customers with a personal coupon code. Your campaign rules will contain a 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 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

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.


Still need help? Get in touch!
Last updated on 11th Jan 2021

Was this article helpful?

Thank you! You have already voted

If you’d like a member of our support team to respond to you, please send a note to support@talon.one