Solved

Unset multiple custom properties at the same time?

  • 18 January 2024
  • 4 replies
  • 82 views

Badge +2

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.  

 

 

icon

Best answer by saulblum 18 January 2024, 23:16

View original

4 replies

Userlevel 4
Badge +7

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

"meta": {

"patch_properties": {

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

}

}

Userlevel 4
Badge +7

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.

Badge +2

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?

Userlevel 4
Badge +7

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.

Reply