Solved

Updating custom profile property when creating an event

  • 14 December 2023
  • 4 replies
  • 147 views

Badge

I’m wondering if it’s possible to add or update profile custom properties using the Create Event endpoint? I’m sending a POST request as described in the docs and including both an existing custom property (with a new value) as well as a totally new custom property, but it seems that the value of the existing custom property isn’t changing, and the new custom property isn’t being added. This is despite being able to see the event show up in the events list for the profile in question.

Here’s the body of the request, and it’s returning a 202 Accepted status.

{
"data": {
"type": "event",
"attributes": {
"properties": {},
"metric": {
"data": {
"type": "metric",
"attributes": {
"name": "Test Event"
}
}
},
"profile": {
"data": {
"type": "profile",
"attributes": {
"email": "matt@emails.com"
},
"properties": {
"Existing Property": 500,
"Totally New Property": "some_value"
}
}
}
}
}
}

Any thoughts on what I might be doing wrong, or whether this just isn’t possible (and a separate Update Profile call would be required to change profile custom properties)?

icon

Best answer by KeviSunshine 14 December 2023, 21:19

View original

4 replies

Userlevel 4
Badge +7

Hi @MattH,

I just tried your API call and the issue is that `properties` needs to be nested inside of `attributes`.

{
"data": {
"type": "event",
"attributes": {
"properties": {},
"metric": {
"data": {
"type": "metric",
"attributes": {
"name": "Test Event"
}
}
},
"profile": {
"data": {
"type": "profile",
"attributes": {
"email": "matt@emails.com",
"properties": {
"Existing Property": 500,
"Totally New Property": "some_value"
}
}
}
}
}
}
}

Cheers,

Kevin.

Badge

Ah, yep, that does it and I’m now able to both add new properties and update existing ones too!

Thanks Kevin, appreciate your help.

Badge +3

I just found this thread and it’s saved me a lot of time.

But, does that mean the JSON example shown on the create_event documentation page is wrong for the JSON request example?

https://developers.klaviyo.com/en/reference/create_event

Badge +3

Another Flow I am upgrading has a webbhook that called the v1-2 identify method.

I changed to https://developers.klaviyo.com/en/reference/create_or_update_profile and, again, the properties array needs moving inside the attributes array to successfully update / create custom profile properties. Which doesn’t match the example given on the documentation page.

Reply