Skip to main content
Contributor IV
January 18, 2024
Solved

Unset multiple custom properties at the same time?

  • January 18, 2024
  • 4 replies
  • 313 views

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.  

 

 

    This topic has been closed for replies.
    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

    Klaviyo Employee
    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
    Expert Problem Solver III
    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.

    kenw232Author
    Contributor IV
    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?

    saulblumAnswer
    Klaviyo Employee
    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.