Solved

Can we use REST APIs to get all Segments?

  • 4 February 2021
  • 5 replies
  • 100 views

Badge

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`?

icon

Best answer by jallain 4 February 2021, 21:34

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

5 replies

Userlevel 3
Badge +2

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.

Badge

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?

Userlevel 3
Badge +2

@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.

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."}

Userlevel 3
Badge +2

@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

 

Reply