Segment api

Hi,
I’m doing my own report page taking data from Active Campaign REST API.
For each list I can get the segment id but there is no method to get the segment name from the segment id. It is a limitation of the API?

Hey @slamp,

Check out the segmemt_list endpoint. It will return an array of all of your segments. Unfortunately the filters parameter will not accept a segment id, so you will have to filter and grab the name from the id on your end. You could do the other way around though if you wanted and filter by name to grab the id.

I just pinged one of our dev team to see if there are any better ways to approach this and will keep you updated.

1 Like

ok thank you,
just to let you understand better, I’m using campaign_list to get all of my campaigns. For each one it give the segmentid.
From this segment id I would like to report the name and the conditions of the segment, like the Details view in the Reports page:

Have this information in REST API this would be very useful

Hi @slamp,

Right now you will need to iterate over the array of segments returned by a second segment_list API call (the segment_list API endpoint will return an array of your segments, see below), to get the details related to the segment_id you are checking for.

So in total you will need something like:

// get your campaigns
var myCampaigns = getAllMyCampaigns(); 
// get your segments
var mySegments = getAllMySegments(); 
// iterate through each campaign

myCampaigns.forEach(function (campaign) {

  // for each campaign, iterate through each segment to see if there is a match
  mySegments.forEach(function (segment) {

    // if there is, then you have the segment details for the segment id of the campaign
    if (segment.id === campaign.segmentid) {

      // do something
      console.log(segment);
    }
  }) 
})

Example of segment_list response:

[
  {
    "id": "37",
    "name": "Segment of Automation 1",
    "automation_id": "4",
    "lists": {
      "1": "1",
      "2": "2"
    }
  },
  {
    "id": "38",
    "name": "Segment of Feature - Weeks to Days",
    "automation_id": "4",
    "lists": {
      "1": "1",
      "2": "2"
    }
  }
]

Now, there is also a secret (undocumented & unsupported. Read: use at your own risk) v3 API that is not released to the public yet, where you can make a segment details call to the ActiveCampaign API.

That looks like {{ your_account }}.activehosted.com/api/3/segments/{{ segment_id }}

Some hints:

  • You don’t need your API url ( {{ your_account }}.api-us1.com ) for v3
  • Send the api key in the header as api-key
  • Some resources have been added to the v3 API, some have not
1 Like

Is the V3 of API already implemented in all account or still need to request/activate it manually…
Love the RESTful approach !

Hey @Viktor_Iwan,

“implemented” is being very generous :wink: but yes, I believe that what is available is available on all accounts. It isn’t case by case so no need to request. If you run into issues on different accounts, you might need to be on the “Contacts & Deals” branch.

Thanks! I think the v3 API will be a breath of fresh air for our developer community!

1 Like

Hi all,

Biannca here from our CX team.

Just an update for anyone that comes across this post, here’s v3 endpoint to retrieve all the segments in your account: https://developers.activecampaign.com/reference/list-all-segments.

From there, if you want to retrieve each individual segment, you can use the ID from the previous call and run this endpoint https://developers.activecampaign.com/reference/retrieve-a-segment.

Please don’t hesitate to reply back out or email us at help@activecampaign.com if you have any further questions.