Solved

How can I export person_id by using their email address?

  • 22 January 2021
  • 20 replies
  • 2061 views

Userlevel 1
Badge +2

I am attempting to isolate the PERSON_ID from accounts by using their email address.

I can get a ‘1’ response from Identify request, but I cannot see the data in the profile

I can see profile data when I use the Profiles API with a known PERSON_ID

 

Essentially, I have a known email address and I want to view the data within that profile.

icon

Best answer by jallain 22 January 2021, 17:02

View original

20 replies

Userlevel 4
Badge +11

Hello @dlshaw9 , if you have a customer’s email address and would like to get their Klaviyo profile ID you can use this URL: 

https://a.klaviyo.com/api/v2/people/search?api_key=API_KEY_HERE&email=EMAIL_HERE

 

You can then use the profile ID that gets returned to update the profile. Hope that helps.

Userlevel 1
Badge +2

Thank you, Jallain! That did exactly the trick

I am now trying to pass a variable into:

GET https://a.klaviyo.com/api/v1/person/{{ PERSON_ID }}

I keep getting 404 NOT FOUND response codes

This is my formatted URL

GET https://a.klaviyo.com/api/v1/person/{ticket.requester.integrations[83684].id}?api_key=XXXXXX

I believe this to be a GORGIAS issue, but any insight into what might be causing the problem from the klaviyo url standpoint?

Userlevel 4
Badge +11

@dlshaw9 it sounds like the request is working but the PERSON_ID you are providing is not one that exists in your Klaviyo account. Are you using the ID of the profile from Klaviyo or the ID from something else?

Userlevel 1
Badge +2

@dlshaw9 it sounds like the request is working but the PERSON_ID you are providing is not one that exists in your Klaviyo account. Are you using the ID of the profile from Klaviyo or the ID from something else?

The data in the GORGIAS import matches the ID in Klaviyo -- I  must just not be pulling the variable address correctly

 

Userlevel 4
Badge +11

@dlshaw9 are you using the Klaviyo public API key or the Klaviyo private API key in your request? Make sure to use the private API key which begins with pk_

Userlevel 1
Badge +2

I removed a bit of my censoring:

GET https://a.klaviyo.com/api/v1/person/{ticket.requester.integrations[83684].id}?api_key=pk_4fXXXXXX

 

Userlevel 4
Badge +11

@dlshaw9 are you able to log the variable to ensure that it is the correct profile ID? Your request URL looks correctly structured and you are getting a response from the API so perhaps the ID is getting pulled incorrectly somehow?

Userlevel 1
Badge +2

That has to be the issue

 

Is a single set of curly brackets the correct syntax to pass that variable (it doesn’t trigger at all with double curlies)?

Userlevel 1
Badge +2

OK so I have confirmed via the Gorgias Macro tool that the variable pulls the right data -- for some reason it does not convert to a string when it passes the url

Userlevel 4
Badge +11

@dlshaw9 There should not be any curly braces in the actual request itself. The URL should look like this:

https://a.klaviyo.com/api/v1/person/AAAAA?api_key=pk_AAAAA

 

Replacing AAAAA with the correct value.

Userlevel 1
Badge +2

Even though I am attempting to pass a variable through?

 

For example, your earlier solution to my initial question to get the id worked with:

GET https://a.klaviyo.com/api/v2/people/search?email={{ticket.customer.email}}&api_key=pk_4f04XXXXXXXXXXXX

 

Userlevel 1
Badge +2

furthermore, I keep getting a 403 Error -  "message": "You must specify an API key to make requests." when I try to pass API through header.

What’s the proper format for the api_key: pkXXXX

 

Userlevel 4
Badge +11

@dlshaw9 What I mean is that the final URL that the request is actually being sent to should not have any curly braces in it where the IDs are supposed to go. The curly braces are a part of whatever language you are using which is trying to interpolate the variable passed into it as part of the string. You may need to use a single or double curly brace to pass in a variable but the final URL string should not contain the curly braces.

 

The 403 error you are getting about the api_key not being specified is probably just a side effect of the URL not being constructed correctly. It is likely being cut off before the api_key is included at the end. You can test the URL by simply entering it into the URL address bar of your browser and if you include the correct profile ID and api_key you will see the JSON of the profile you are asking for.

Userlevel 1
Badge +2

I really appreciate your help! I can confirm the variable is correct -- the JSON just isn’t translating it to the url

Userlevel 4
Badge +11

Here are the docs for the Profiles API: https://www.klaviyo.com/docs/api/people

 

I don’t see it mention that you can pass the api_key as a header to that API. I know other APIs of ours accept it as a header but this might only accept it as key=value pairs in the URL itself.

Userlevel 1
Badge +2

Excellent. Just making sure I wasn’t missing something -- thank you.

Do you know of anything in my URL that Klaviyo API requires for a variable.

 

For example in my successful variable URL:

GET https://a.klaviyo.com/api/v2/people/search?email={{ticket.customer.email}}&api_key=pk_4f04XXXXXXXXXXXX

 it has the “search?email=” string -- I know I am just grasping at straws now, but it is driving me crazy haha

Userlevel 4
Badge +11

@dlshaw9 This URL has a similar structure to that one as well. It ends:

/person/AAAAA?api_key=pk_BBBBB

The AAAAA is the variable in this case for whatever profile ID you are trying to get. the BBBBB can be replaced with your API key.

Did you test the URL in the browser like I mentioned in a previous message? If you take the whole URL and enter it into the browser and hit enter are you seeing the JSON of the profile displayed? Here is an example of what I mean:

 

Userlevel 1
Badge +2

Yes I was -- I think everything on your end is functioning perfectly. It appears as if something is broken with the variable transformation of the JSON request in Gorgias.

 

Thank you for all of your help!

 

Badge +1

Hi @dlshaw9 hope you’re well, i’m looking for some help and you might be able to help :-)

It’s fairly simple: we want to implement a preferences form hosted by Klaviyo but we can’t pass the email address over from account to the form, so want to do a check to make sure the customer has entered the correct email and that they already exist as a profile in Klaviyo.  From my research I can see this may be possible by creating a custom-built form and utilising the API to verify the email.  Do you think that utilising person_ID might be a solution to this?

Badge +1

@dlshaw9 did you get this working in the end, i think i am trying to do the same thing as you.
it is incredibly frustrating that you cant GET the person by email in just one call, do i take it that you have done two separate integrations, the first one to get the person_id via email and then the second one to get the person via the id

did you get the second one working, if so, pleasde could you share an obfuscated url example, using gorgias variables, thanks
 

Reply