Solved

Clearing property value via API

  • 22 March 2022
  • 9 replies
  • 965 views

Badge +2

I am able to set Klaviyo and custom properties with API calls but cannot clear/blank out the property value. I can not do it through the interface or with the API.  For example if I set Location to “NY” and want to then set it to blank, neither the interface or API will allow it.  Through the interface I can remove the property.  I would prefer blanking it out but if that is not possible is there a way to remove the property through the API?

icon

Best answer by David To 23 March 2022, 15:03

View original

9 replies

Userlevel 7
Badge +60

Hello@John99,

Great question!

You can certainly remove profile properties through API using the $unset command as @julie.accardo mentioned in the Community post below:

In addition, you can also use something like the following if you were working with an identify  request, or whatever values you have in properties set in the customer_properties  section of a track request:

{
"token":"abc123",
"properties":{
"$email":"person@email.com",
"$unset":["property_to_unset_key"]
}
}

I hope this helps!

David

Badge +2

David - Thank you! I was able to do what I needed to do.

Badge

Hi,

I’m using Revision: 2023-01-24 and cannot get $unset to work. There’s also no reference to it in the API docs https://developers.klaviyo.com/en/reference/api_overview

Does this feature no longer work or is there a new alternative? 

Userlevel 7
Badge +60

Hey @nick1,

Great observations! 

Since the launch of our new APIs, the previously undocumented $unset feature is actually out of scope. The new behavior to clear/unset an existing profile property is to set it to null. 

David

Badge

Thanks for your help David!

Before finding out about $unset I had actually already tested submitting a null value. This didn’t delete the property unfortunately, it was still listed but with None presented as it’s value. Is there a way to remove the property completely so it doesn’t appear at all?

Userlevel 7
Badge +36

Hi @nick1!

 

For now, the only ways to remove properties entirely are to use the legacy API’s $unset property or delete them in the UI dashboard.

 

However, our product team is aware of the demand for this feature in the new APIs, so I will update the thread if anything similar becomes available in the future. 

 

I hope this helps to clarify!

- Brian

Badge +3

Would love to see/hear of a way to remove profile properties via new API

Userlevel 7
Badge +36

Hi @mscheurichpatou!

 

I’ll definitely forward this feedback to our Developer Experience team and update the thread when there are more updates!

 

- Brian

Userlevel 3
Badge +4

Hi @nick1 @mscheurichpatou and @John99!

It is possible to completely remove a profile property in our APIs as of the 2023-07-15 revision using meta.patch_properties : https://developers.klaviyo.com/en/docs/changelog_#improved-endpoints

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

If I had previously created a profile with a custom property called “FunFact”, I could completely remove that from the profile using the following payload in a call to the Update Profiles endpoint. 

{
"data": {
"type": "profile",
"id": "PROFILE_ID_TO_UPDATE",
"meta": {
"patch_properties": {
"unset": "FunFact"
}
}
}
}

You can also append an item to a custom list property like so: 

{
"data": {
"type": "profile",
"id": "PROFILE_ID_TO_UPDATE",
"meta": {
"patch_properties": {
"append": { "listProperty": "itemToAdd" }
}
}
}
}


Or you can remove an item from a custom list property like so: 

{
"data": {
"type": "profile",
"id": "PROFILE_ID_TO_UPDATE",
"meta": {
"patch_properties": {
"unappend": {
"listProperty": "itemToRemove"
}
}
}
}
}

 

Reply