Solved

Adding a new member to a list via API with first name doesn't work

  • 16 February 2022
  • 7 replies
  • 789 views

Badge +2

Hello,

I set up a form to subscribe users to a list. I use the API for that. It works when i only add the email to the payload, using the https://a.klaviyo.com/api/v2/list/LIST_ID/subscribe?api_key=API_KEY endpoint.

I closely follow the docs, using Guzzle (PHP)

But when i try to add a first name to the profile, it doesn”t seem to work.

  1. Using the list → subscribe endpoint, i don’t know if it’s possible, and if it is, the expected body request (the one working with the email looks like this :
    'body' => '{"profiles":[{"email":"' . $email . '"}]}'
  2. Using the identify endpoint (POST), the request returns 1, but no firstname is added to the profile
    'data' => '{"token":"MYPUBLICKEY","properties": {"$email": "THEEMAIL", "$first_name":"THEFIRSTNAME"}}'
  3. Using the list → members endpoint, i get a 400 Bad Request as soon as i deviate from the base body request with email AND phone number
    'body' => '{"profiles":[{"email":"THEEMAIL"},{"first_name":"THEFIRSTNAME"}]}'

Can you please help me with that issue ?

Thanks !

icon

Best answer by alex.hong 16 May 2022, 23:27

View original

7 replies

Userlevel 7
Badge +58

Hi there @jblouvet,

I see a ticket has been opened for your case and a team has reached out to you. I would check your emails to ensure you got their solution.

 

Thank you!
Alex

Badge +2

Hi Alex,

Thanks for the reminder. The problem is solved, it was a simple mismatch in the formatting of the data, due to extreme fatigue :).

Cheers,

JB

Badge

Hi

I have a similar problem

If I use: 

{
"profiles": [
{
"email": "john.smith@domain.com"
}
]
}

It works fine and creates the name automatically

but as soon as I try to set the first name like so 

{
"profiles": [
{
"email": "john.smith@domain.com"
},
{
"first_name": "Jonathan"
}
]
}

it gives me a response of {"detail":"email or phone number is a required field for each profile"}

Note: I do not have a custom ‘first_name’ field I just want to set the default profile first name/last name with data submitted from my form

What am I doing wrong 🙂 Thanks

Userlevel 7
Badge +58

Hello @nickstaw,

This might be a formatting issue that we can sort out quickly. If you check out our api docs, we are sending a list [] full of profile objects {}. Each set of curly brackets represents 1 profile, and should contain all the properties for that profile. In the example request you sent over, it was technically attempting to subscribe 2 separate profiles (1 of which have no email or phone number). All the fields for one profile should be encapsulated into one set of curly brackets. This is an example where I am including two profiles in the request, this shouldn't raise an error because each profile has either an email or a phone number:

?name=inline111349058.png

 

Hope that helped,

Alex

Badge

Hi Alex 

Thanks that worked! I did try that before but I think I had a dodgy “ in the JSON which was throwing a formatting error! 

Kind Regards

Nick

I’ve just been hit by this. I think your example in the API documentation could be much clearer if you just add a second email address to the second profile - then it’s obvious it’s two profiles being registered of two different people. 

 

I have to confess I missed it was an array and I should have guessed - but if there’s ambiguity then it has room to be clearer and save us poor devs some fingernails. 

Userlevel 7
Badge +60

Hey @siempreSteve,

Thanks for sharing this feedback! I’ll pass it along to our documentation team!

Thanks for being a part of our Klaviyo Community.

David

Reply