Hi @sourabh - In the example you showed, you specified a specific LIST_ID and I think that’s for getting all the emails/phones excluded for that List - so not sure if you’re using the right API endpoint.
Did you try the example from the API Reference below? (remember to replace your API_KEY
)
import requests
url = "https://a.klaviyo.com/api/v2/lists?api_key=API_KEY"
headers = {"Accept": "application/json"}
response = requests.request("GET", url, headers=headers)
print(response.text)
Also, I can’t remember the API returns Inactive Segments (or not) - so you may want to make sure the Segment is not Inactive too. Let us know if this works!
Thank you for flagging my mistake @retention. I actually used the endpoint mentioned in the Get Lists
:
import requests
url = "https://a.klaviyo.com/api/v2/lists?api_key=API_KEY"
headers = {"Accept": "application/json"}
response = requests.request("GET", url, headers=headers)
print(response.text)
And with this endpoint, I am only receiving a list of all the lists and not segments.
@sourabh - Ah - I figured out why I thought it returns a List of Segments as well as List. Apparently, in V1 of the API, it use to do that but was removed in V2. You can see this thread here:
Try changing your Endpoint to V1 (if it’s still available?) and see if it works? Just be caution, if it does, it’s technically a deprecated function. I assume Klaviyo wants to build a function for just Segments (separate from Lists) at some point in the future?
Since the developer portal updated, I can’t find the V1 documentation, but you can see a list of all functions & deprecated functions here:
https://klaviyo-openapi.s3.amazonaws.com/deprecated.json
https://klaviyo-openapi.s3.amazonaws.com/spec.json
That’s really helpful @retention. Thank you very much.