Solved

Looking up sms consent details with api

  • 4 January 2021
  • 8 replies
  • 505 views

Badge +2
  • Contributor I
  • 2 replies

Hi, does anyone know if it’s possible for me to lookup whether a user has consented to sms or not with the api using just the email address?

 

Thanks

icon

Best answer by k.mcevoy 4 January 2021, 20:50

View original

8 replies

Userlevel 4
Badge +6

Hi there, 

Thanks for being a member of the Community!

 

You should be able to retrieve a profile’s SMS consent using this endpoint: 

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

As outlined in this documentation.  The endpoint requires the person_id and if the retrieved payload includes “sms_consent”: True they have opted into SMS. More information on that here

 

Kelsey

Badge +2

Thanks for the reply. The issue I’m having is that in our db we don’t have the person_id stored, just information from shopify (customer info, email etc). Is there a way to do this with the email address instead of the id? If not is there a way to retreive the person_id via api using the email address to lookup?

 

Thanks

Userlevel 4
Badge +6

Got it! 

 

If you just have email address you should be able to make the following request: 

curl -X GET \  https://a.klaviyo.com/api/v2/people/search \  -H 'api-key: 'YOUR_PRIVATE_KEY' \  -d '{"email":"EMAIL_ADDRESS"}'

 

Just as a reminder we have an API limit of 3 calls/second. 

 

Kelsey 

Badge +2

Hi, thanks. The lookup works great. However once I get the person_id on the one I’m testing when I look it up with GET https://a.klaviyo.com/api/v1/person/{{ PERSON_ID }} 

 

I don’t see “sms_consent”:true even though the person signed up through a klaivyo sms form and I see consent when I look them up in klaviyo :/

 

 

Userlevel 4
Badge +6

Hi @AR99  

Would you mind passing along an example request so I can take a closer look? 

Thanks so much!

Kelsey 

Badge +2

Got it! 

 

If you just have email address you should be able to make the following request: 

curl -X GET \  https://a.klaviyo.com/api/v2/people/search \  -H 'api-key: 'YOUR_PRIVATE_KEY' \  -d '{"email":"EMAIL_ADDRESS"}'

 

Just as a reminder we have an API limit of 3 calls/second. 

 

Kelsey 

I tried this api but I’m getting only person id in return: 
https://a.klaviyo.com/api/v2/people/search?api_key={{APIKey}}&email={{email}}

So after getting personId from above API, I tried to call GET https://a.klaviyo.com/api/v1/person/{{ PERSON_ID }} API. But I’m not getting sms consent status even though passed person Id has this value as true. There is no consent related field in API response.

Badge +2

Hi, thanks. The lookup works great. However once I get the person_id on the one I’m testing when I look it up with GET https://a.klaviyo.com/api/v1/person/{{ PERSON_ID }} 

 

I don’t see “sms_consent”:true even though the person signed up through a klaivyo sms form and I see consent when I look them up in klaviyo :/

 

 

Hi, did you manage to get sms_consent status using this api? Because I’m receiving only personId in response.

Userlevel 7
Badge +60

Hello @AR99 and @himalay,

Adding to @k.mcevoy, I would recommend try using the Check List Subscriptions endpoint below. 

https://a.klaviyo.com/api/v2/list/LIST_ID/subscribe

Using this endpoint will allow you to list out emails, phone numbers, or push tokens in the body of the request.

If the request returns a response with their phone number; this would indicate that the profile has consented to receive SMS. Invalid requests will be accompanied by an error message.

From the example above, we can see that the "phone_number" is included in the customer object in the response. You may also want to reference our API Documentation surrounding this endpoint here: https://apidocs.klaviyo.com/reference/lists-segments#check-subscriptions

Hope this helps!

-David

Reply