Skip to main content
Solved

Can we use REST APIs to get all Segments?

  • February 4, 2021
  • 5 replies
  • 455 views

Forum|alt.badge.img+2

We are trying to fetch list of all the `Lists` and `Segments` we have and then fetch members in all the `Lists` and `Segments` using the `Group` API. We are able to do this successfully for `Lists`, we couldn’t find any API to GET details of all our `Segments`.

Is there any way we can achieve this?

Or is there any way we can directly get list of all Members in all `Lists` and `Segments`?

Best answer by jallain

Hello @pkskypointcloud 

 

You should be able to get all of the List and Segment IDs using this URL:

https://a.klaviyo.com/api/v1/lists?api_key=****

 

Then, using a Segment ID, you can get the members of that segment with this URL:

 

https://a.klaviyo.com/api/v2/group/SEGMENT_ID/members/all?api_key=***

 

Make sure to replace the SEGMENT_ID and use the Klaviyo private API key in the requests.

View original
Did this topic or the replies in the thread help you find an answer to your question?

5 replies

jallain
Klaviyo Employee
Forum|alt.badge.img+11
  • Klaviyo Employee
  • 70 replies
  • Answer
  • February 4, 2021

Hello @pkskypointcloud 

 

You should be able to get all of the List and Segment IDs using this URL:

https://a.klaviyo.com/api/v1/lists?api_key=****

 

Then, using a Segment ID, you can get the members of that segment with this URL:

 

https://a.klaviyo.com/api/v2/group/SEGMENT_ID/members/all?api_key=***

 

Make sure to replace the SEGMENT_ID and use the Klaviyo private API key in the requests.


Forum|alt.badge.img+2

Hey @jallain , the API https://a.klaviyo.com/api/v1/lists?api_key=**** is only returning us the Lists. Do we need to do some configuration to have it return segments too?

UPDATE: We are using v2 of the API. I guess it does not return segments yet. Is it recommended to use v1 in prod since the page mentions i’s DEPRECATED and asks to use v2?


jallain
Klaviyo Employee
Forum|alt.badge.img+11
  • Klaviyo Employee
  • 70 replies
  • February 8, 2021

@pkskypointcloud  For now you should be fine to use the V1 API for that request to get Segment IDs. I would keep using V2 everywhere that you can for other requests.


Forum|alt.badge.img+1
  • Contributor I
  • 1 reply
  • June 7, 2021

this api not responding properly

https://a.klaviyo.com/api/v2/group/SEGMENT_ID/members/all?api_key=***

I am passing List_ID and api_key properly when call
it is giving below response when called:=
{"message":"An internal API server error occurred. Please contact support@klaviyo.com."}


jallain
Klaviyo Employee
Forum|alt.badge.img+11
  • Klaviyo Employee
  • 70 replies
  • June 7, 2021

@roslyn This call works fine for me. Are you still getting that error? Double-check that the API key and List ID are correct and from the same account.

 

Postman request