Solved

Identify Profile API (check if profile exists with email)

  • 28 September 2021
  • 3 replies
  • 1053 views

Badge +2

Hi all,

I need to check if a profile exists on my custom form submission. I already have the custom form submitting to Klaviyo through an API call. What I’d like to do is add another call before this, and check if the email exists already.

 

I’m attempting to use the example shown here: https://apidocs.klaviyo.com/reference/track-identify#identify-get

 

When I run this code, it returns a 1 every time, whether the email / profile exists or not.

Is there a way to check if the profile exists through this endpoint?

 

const options = {
method: 'POST',
headers: {Accept: 'text/html', 'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
data: '{"token": "PUBLIC_KEY","properties": {"$email":"ben.franklin@klaviyo.com"}}'
})
};

fetch('https://a.klaviyo.com/api/identify', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));

 

Many thanks for any advice.

icon

Best answer by Dov 30 September 2021, 15:24

View original

3 replies

Badge +2

I should mention I’m also open to other means of doing this. I’m just hoping to avoid having to create a solution with a private API key.

Here’s the code I’m using to add the user to our list:
 

const settings = {
"async": true,
"crossDomain": true,
"url": "https://manage.kmail-lists.com/ajax/subscriptions/subscribe",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache"
},
"data": {
"g": listID, // list ID is variable
"email": emailInput // email from input
}
}

$.ajax(settings).done(function (response) {
// form success stuff
});

 

This works without problem. 

GOAL: Add an additional check before running this to see if email already exists.

Badge +2

As a final follow up… if you read this & think this isn’t possible with a public API key, please let me know. I can dig into doing this with GraphQL, but hoping for a quicker solve.

Userlevel 7
Badge +61

Hi @bethanyfish,

Thanks for sharing this question with the Klaviyo community.

The only other way is to use the Lists API endpoint to look for the Profile IDs of multiple profiles in a list/segment: https://www.klaviyo.com/docs/api/v2/lists#get-members-all

You can create a segment of everyone in your account with the following segment logic: Properties about someone > email contains > @. 

Reply