Skip to main content
Solved

Unset multiple custom properties at the same time?

  • January 18, 2024
  • 4 replies
  • 254 views

Forum|alt.badge.img+3

We’re using the API to unset a custom property.  This works:
 

    $data = '{"data":

    {

            "type":"profile",

            "id":"01GGQ27017WQ2K1H52ZJTZ40T9",

            "attributes":{},

            "properties":{},

            "meta": { "patch_properties": {"unset": "Something"} }

    }}';  

 

Is there a way to unset many at the same time?  We don’t want to have to make 10 API calls to unset 10 properties.  

 

 

Best answer by saulblum

Is it possible to rename existing properties?  Like if Age = 25 can I rename Age?  or do I have to delete and re-add a new one?

Not as far as I know, you’d have to delete the existing property and set a new property with the new  name.

4 replies

Forum|alt.badge.img+7
  • Klaviyo Employee
  • 182 replies
  • January 18, 2024

You can pass in an array of property names, e.g.

"meta": {

"patch_properties": {

"unset": ["prop1", "prop2"]

}

}


KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 160 replies
  • January 18, 2024

Hi @kenw232,

Are you looking to completely remove the properties, or just set them to null? You can set the properties to null directly in the `attributes.properties` object, like this:

{
"data": {
"type": "profile",
"id": "{your profile ID}",
"attributes": {
"properties": {
"any_custom_field_you_want1": null,
"any_custom_field_you_want2": null
}
}
}
}

Important to note that properties is a field nested within attributes rather than top-level.

I haven’t tried the meta approach, but will try that shortly. Let me know if the `null` approach suffices though!

 

*edit: see @saulblum’s answer

{
"data": {
"type": "profile",
"id": "{ID}",
"attributes": {
"properties": {}
},
"meta": {
"patch_properties": {
"unset": ["your_field1", "your_field2"]
}
}
}
}

 

Cheers,

Kevin.


Forum|alt.badge.img+3
  • Author
  • Contributor IV
  • 12 replies
  • January 18, 2024

Is it possible to rename existing properties?  Like if Age = 25 can I rename Age?  or do I have to delete and re-add a new one?


Forum|alt.badge.img+7
  • Klaviyo Employee
  • 182 replies
  • Answer
  • January 18, 2024

Is it possible to rename existing properties?  Like if Age = 25 can I rename Age?  or do I have to delete and re-add a new one?

Not as far as I know, you’d have to delete the existing property and set a new property with the new  name.