Solved

Constantly updating a custom property with new values via API

  • 25 August 2023
  • 2 replies
  • 135 views

Badge +1

With our current integration we are passing a custom field to a Klaviyo contact called “promotion_id” which identifies which of our promotions they came through. 

For example, promotion_id: 2715

If that same email address enters another promotion, it will automatically update the promotion_id field with the ID of the new promotion, overwriting the old value. 

How do we keep the old value and add a new value, WITHOUT having to first lookup what values currently exist?

Ideally, as customers enter different promotions, we can just keep adding new values to the promotion_id field. However, after reading through the API docs, it appears we have to first look up the user to see what values already exist for the promotion_ID field, and pass all the values through? Is there anyway around this to not have to make that extra API call?

icon

Best answer by Kim Strauch 26 August 2023, 01:04

View original

2 replies

Hi there,
Did you want to keep the old values and add the new custom property as well, or overwrite the old value with the new one?

I recommend checking out Patch Profile endpoint and particularly the append/unappend objects.

https://developers.klaviyo.com/en/reference/update_profile

Userlevel 3
Badge +4

+1 to @wanttoknowallaboutecommerce’s answer. See this answer for a bit more detail on these properties: 

Note: if you’re working with an existing custom property that is not a list, you’ll first need to update it to be a list to be able to take advantage of this append functionality. If starting fresh, you can just always use “append” which will create the property if it doesn’t exist or append to it if it does exist. 

If you are trying to update this field when creating an event, you should be able to follow a similar pattern using the  profile.meta.append object.  See https://developers.klaviyo.com/en/reference/create_event

Reply