Solved

Getting coupon codes dynamically from a URL or API

  • 5 April 2024
  • 2 replies
  • 31 views

Userlevel 2
Badge +5

Hi,

I’m aware that there’s been activity surrounding this issue on WooCommerce, but wondered if it’d been tackled for custom integrations.

tl;dr - in Klaviyo emails, can we get a coupon code dynamically at send time from our own web service, providing a customer ID as an argument?

Many thanks,

Gareth

- o O o -

Detail:

Back ages ago when I handled all emails myself, I had a class that created single-use, customer-locked coupon codes with expiration dates. When I was generating emails, the process would call the class, get a code, and include it in the email.

We’re now looking to incorporate the same logic in a Klaviyo flow. We can do 90% of it just fine - import a list of single use codes as per documentation etc. Problem is we’d like them to expire three days after the email is sent. This means either that when the email is sent it needs to make a call to my server to say ‘please expire GXC34567dfghj in three days time’, or, much simpler, just request a 3-day-lifetime single use customer-locked code direct from my website via a web service call.

The current proposed workaround is to put a URL in the email, ‘go here to get your code’, which sends them to a page which creates a code for them that has an expiry date, but management aren’t happy with this: they want the code direct in the email with no intermediate steps.

I could do this as a dynamic image src, but that’s not copy-pasteable and would be subject to remote content being blocked in emails etc etc.

icon

Best answer by retention 5 April 2024, 17:55

View original

2 replies

Userlevel 7
Badge +58

Hi @dartacus, welcome to the community.

I haven’t dabbled much in the Custom Coupon API, but there seems to be endpoints to now support this if you want to develop the process natively.  

See this API Endpoing:

It seems like you can generate a unique coupon code, for a specific user, and set an expiration - at runtime?? I’ll leave it to you to see if it works the way you expect it, or if it’s still the old model of managing bulk uploads, etc. 

Even with bulk uploads method only, perhaps you can still use the API to replace the list of coupons each day on a daily cron job with a new set of coupons that expire in the future, so anyone that receives an email that day will get a coupon code from the fresh batch.  

Here’s the high level guide to Custom Coupon API:

Also see @ludvigisaksen  unique solution of doing this in a prior thread.  He uses a combination of webhooks and Zapier to build a coupon code with a specific convention to generate coupon codes that have expirations.  

I also do wish Klaviyo would just make this a native feature, but I can imagine WooCommerce may have more complexity due to the fact that its more customizable by developers and its backend code may not be uniform across all merchants for a common solution to work.

Hope that helps get you started on this!

Userlevel 2
Badge +5

Thank you, I’ll look into the API for this.

G

Reply