Skip to main content
Solved

How to update existing "Custom Properties" value of profile with API?


Forum|alt.badge.img+2
  • Problem Solver I
  • 3 replies

I have an event flow that creates a custom property for the user called “latestPoem” and sets it with a generic value. Now that I have this custom property in the users profile I would like to update the value for it using a custom variable that contains a unique short poem related to the user. 

From my understanding this should be possible using the identify API but I am getting the result 0 when I try to do this:

'data', `{"token": "${token}","properties": {"$email":"${email}", "latestPoem": "${poem}"}}`)

When I remove the variable latestPoem I get a result 1 meaning success:

'data', `{"token": "${token}","properties": {"$email":"${email}"}}`)

Does the identify API not support the updating of custom profile properties? From my understanding it does. Is there another way to do this? Am I formatting my request incorrectly? Do I need to use a different API? 

Best answer by PoemAI

So I’ve figured out the issue! My ${poem} variable unfortunately has newline characters which breaks the url encoding.

Unfortunately this is a bit of a tricky issue now as I’ll have to figure out how to format the users poem nicely in an email campaign but at least there is progress…

View original
Did this topic or the replies in the thread help you find an answer to your question?

6 replies

Forum|alt.badge.img+5
  • Problem Solver I
  • 15 replies
  • March 1, 2023

Hi @PoemAI,

I’ve just attempted your call with success. I’ve added a property called “latestPoem” to a customer profile. The only place I could see a difference is if the value “${poem}” isn’t escaped properly or something.

Try hard coding that poem value as a test. You might find the issue there.


Hi there,
I’d recommend using this endpoint to update the profile property: https://developers.klaviyo.com/en/reference/update_profile (server-side)
or
this endpoint : https://developers.klaviyo.com/en/reference/create_client_profile for publicly-browseable, client-side environments only.

Here is how to update a property using the flow in the UI:
https://help.klaviyo.com/hc/en-us/articles/360001768432


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 3 replies
  • March 2, 2023
jjensen_ksp wrote:

Hi @PoemAI,

I’ve just attempted your call with success. I’ve added a property called “latestPoem” to a customer profile. The only place I could see a difference is if the value “${poem}” isn’t escaped properly or something.

Try hard coding that poem value as a test. You might find the issue there.

@jjensen_ksp good point!

 

So I’m hardcoding the value “${poem} as “To be or not to be” and receiving a 1 but it isn’t actually updating on the users profile. 


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 3 replies
  • Answer
  • March 2, 2023

So I’ve figured out the issue! My ${poem} variable unfortunately has newline characters which breaks the url encoding.

Unfortunately this is a bit of a tricky issue now as I’ll have to figure out how to format the users poem nicely in an email campaign but at least there is progress…


Forum|alt.badge.img+5
  • Problem Solver I
  • 15 replies
  • March 2, 2023

@PoemAI can you replace your newline chars with %0A?


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 3 replies
  • March 2, 2023
jjensen_ksp wrote:

@PoemAI can you replace your newline chars with %0A?

I tried this… sadly its still not formatting %0A even with the pre tag. At this point I’m probably going to have to look into somehow storing the poem value as a list.