Example Usage of
 segment_list

Segment information

Description: Obtain individual segment metadata (the segments themselves).
Endpoint: https://{ACCOUNT}.api-us1.com/api/2/segment/list
HTTP method: GET
Supported output formats: json
Requires authentication: Yes
Parameters:
* indicates requirement. Underlined params include in URL, otherwise as part of the post body. POST data must be formatted as
Content-Type: application/x-www-form-urlencoded
. We don't accept any other input formats like JSON.
Variable Description
api_key*Your API key
filtersArray of optional filters to narrow down the results returned. Acceptable filters are "name", "automation_id", and "list_id".
sortField to sort the data by. Acceptable sort fields are "id" and "name" (the default is "id" if this parameter is not included).
sort_directionThe direction to sort by. Acceptable values are "ASC" or "DESC" (the default is "ASC" if this parameter is not included).
pageThe page of data to fetch. Pages are limited to 20 results.
Example response:
Variable Description
id4
nameTest
automation_id11
listsArray

PHP Example

This is an example of using the segment_list call with PHP. You can replicate the same idea in virtually any other programming language. This example requires our PHP API wrapper. Make sure to update the path to the wrapper files in the example code below (if it is not the same).

 <?php

// Set up an object instance using our PHP API wrapper.
define("ACTIVECAMPAIGN_URL", "https://{ACCOUNT}.api-us1.com");
define("ACTIVECAMPAIGN_API_KEY", "{API_KEY}");
require_once("../activecampaign-api-php/includes/ActiveCampaign.class.php");
$ac = new ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY);
$ac->version(2);

$params = array(
	"filters" => array(
		"name" => "Attendees", // Exact match search.
		"list_id" => 2, // Associated with at least this list.
		"automation_id" => 12, // Associated with this automation.
	),
	"sort" => "id",
	"sort_direction" => "ASC",
	"page" => 1,
);
$params = http_build_query($params);

$response = $ac->api("segment/list?$params");

echo "<pre>";
print_r($response);
echo "</pre>";

?>

Questions? Discuss this API call in our developer forum

You can install activecampaign-api-php by downloading (.zip) or cloning the source:

git clone git@github.com:ActiveCampaign/activecampaign-api-php.git