Solved

Updating custom profile property when creating an event

  • 14 December 2023
  • 6 replies
  • 206 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

6 replies

Userlevel 4
Badge +8

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 +5

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 +5

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.

Userlevel 4
Badge +6

Hey @teamcooperuk! I think these are showing in the correct spot in the JSON examples for both, but please let me know / share screenshots if you’re seeing something different on your end. 

For Create Event, there are actually two properties keys in play. One that is used for event properties and one that is used for profile properties. The profile properties key appears in the correct spot for me:



For Create or Update Profile, I’m seeing properties under attributes:

 

Badge +5

I see my mistake now - I don’t generally have to use the location object, and with that removed it meant I missed the correct positioning.

Reply