Skip to main content

When I use this endpoint, any custom properties I try to create have their values transformed into an array that holds that value as its first value. Does anyone know a workaround or a way to escalate this to engineering to fix?
https://developers.klaviyo.com/en/reference/create_or_update_profile

Example:

$payload = [
'data' => [
'type' => 'profile',
'attributes' => $attributes,
'meta' => [
'patch_properties' => [
'append' => [
'GN_custom' => 'value goes here',
],
],
],
],
];
$response = $this->client->Profiles->createOrUpdateProfile($payload);


I would expect my custom property `GN_custom` to have a value of "value goes here" but instead it is wrapped in an array like this ["value goes here"].

At first I thought it was a problem with the PHP SDK that we’re using, but after debugging it appears to be just the way the API endpoint handles custom properties. IMO it’s broken.

Thanks in advance!

Hey ​@sgruenholz 

I am not entirely sure about this, but can you try to use the set operation instead of append. The set operation replaces or sets the value of a property without wrapping it in an array.

$payload = d
'data' => g
'type' => 'profile',
'attributes' => $attributes,
'meta' => g
'patch_properties' => g
'set' => g
'GN_custom' => 'value goes here',
],
],
],
],
];
$response = $this->client->Profiles->createOrUpdateProfile($payload);

let me know if this works.

thanks

Arpit


Thanks for the suggestion! I tried that but the API fails with a 400 Bad Request. 

Based on the descriptions in the docs, it sure seems like I’m using the correct signature. They only list three patch commands: 

  • append
  • unappend
  • unset

 


OK, after doing some more testing, I finally figured out a combination that works:

  1. Set the properties array in the attributes. (This is the first thing I tried but doesn’t work by itself)
  2. In the meta you must both `append` and `unappend` those same properties.
// email, name, etc go in here.
$attributes = ];

$properties =
'winner' => "chicken dinner",
];

$attributest'properties'] = $properties;

$payload =
'data' => t
'type' => 'profile',
'attributes' => $attributes,
'meta' => t
// You have to append and then unappend the same properties
'patch_properties' => t
'append' => $properties,
'unappend' => $properties,
],
],
],
];

$response = $this->client->Profiles->createOrUpdateProfile($payload);

And the custom properties finally get set correctly.

Really weird way to do things but it works. Hope this helps someone else!


Reply