Skip to main content

Hello! I am looking to send a campaign to a certain segment of customers. This campaign needs to have a unique key (text string) sent to each customer.

Ideally, Klaviyo’s campaign automation would—for each email—hit our dedicated API endpoint to generate the unique key, then leverage the API response to integrate the key into the template. Is this possible?

In my research so far, it seems that the above approach is not an option. So the next best option would be to first assign keys to those customers’ profiles (as custom profile properties) whenever they join the aforementioned segment. It seems that the best way to do that, is by using Klaviyo’s Code feature. I think I can achieve this by using event:klaviyo.subscribed_to_list as the function trigger, filtering only events that fired from the target segment.

This is where my problem lies. Assuming the first approach is impossible, I am now faced with the problem of Klaviyo Code seemingly not having any comprehensive documentation. Am I missing something? All that I’ve been able to find is the “Getting started with Code” help article, where the example code doesn’t really lend to my use case. Problems:

  • I am using Node.js and can’t find any details or docs on how to use the klaviyo-api module for Code
  • Code itself does not seem to have any thorough docs

If there’s a better way to do what I’m trying to do, please tell me. Or at least guide me to where these elusive docs are. Thanks!

 

- Reavo

Update:

I did find the Node.js klaviyo-api module’s docs here. They’re still not fully comprehensive (i.e. very few complete examples or definitions of function arguments). But combined with the Klaviyo API reference, I can piece together most of the code I need.

New issue: event:klaviyo.subscribed_to_list does not fire when a profile is added to a segment. So now, as far as I can tell, I’ll have to go outside of Klaviyo and create an external code snippet that bulk-writes a new custom event to every profile in the segment. Then we’ll need to manually run that code snippet from time to time...

This is getting way hairier and less automated than I had hoped. If anyone else can point me in a more concise direction, I’m all ears.


Hey ​@ReavoEnd,

If you’re using the code action within a flow, you can just create a segment-triggered flow instead of a list-triggered flow, and that should fix the issue! While there’s no “subscribed to segment” or “entered segment” event, our flow builder has segments as an option for the trigger. You could add a code option right under the trigger in a segment-triggered flow.

To confirm you’re on the right track, the Create Event doc is the go-to when you want to create an event that adds profile properties to a profile in Klaviyo. This API can add custom properties to profiles when it fires, which would allow you to use those properties in emails/SMS/segments.

Let me know if I can answer any additional questions.

 


Thanks for the response, ​@Byrne C.

While it does sound ideal to use a code action within a Flow triggered by “Added to Segment”… I do not see such a “Code" option in our Flow editor. Am I missing something?
 

 


I see a viable path in adding a custom action to a flow. However, our Klaviyo account is not eligible as we are roughly 80k active profiles shy of the 400k active profile requirement. Is support able to make exceptions on this…?

the desired feature is blocked for us.

For posterity, we have been able to achieve a subpar solution by leveraging various Klaviyo API calls in Python. We fetch the list of profiles currently in the target segment, use our own API to generate a code for each one, then assign the codes to each profile as custom properties.

Said solution is subpar because it must be run manually every so often, then followed by manual creation and sending of a Campaign. Leveraging a custom action in a flow would eliminate those manual elements.


Hi ​@ReavoEnd,

The code option in flows is only available for those on an Advanced KDP plan, unfortunately, so that won’t be available if you don’t have that plan. I did reach out to our team to see if the custom action feature can be added to your account, but I can’t guarantee that we’ll be able to enable this. That being said, I’ll keep you in the loop and let you know if this is possible!


Hi ​@ReavoEnd,

Just sent you a DM regarding your question about custom actions!