Creating segment from the API
Published 09/24/2008 by Hendri Kurniawan
Over the coming days I will be explaining on how to manipulate segments using the API.
Today, I will explain to you on how to create segment using the API. When using the API to create segments, you will be able to create a more powerful filtering than using the standard UI in IEM.
require_once (SENDSTUDIO_API_DIRECTORY . '/segment.php');
$segment = new Segment_API();
// Owner ID of the new segment
$segment->ownerid = 1;
// Current time
$segment->createdate = AdjustTime();
// Segment name
$segment->segmentname = 'Test Segment';
// Segment search information
$segment->searchinfo = array(
// The list of which the segment will apply it's rule
// This is an array of list Ids
'Lists' => array(49),
// Segment rules
'Rules' => array(
array(
'type' => 'group',
'connector' => 'and', // Connector for the next group
'rules' => array(
// --- These are the rules that will be applied to the list
array(
'type' => 'rule',
'connector' => 'or', // Connector for the next rule
'rules' => array(
'ruleName' => 'email',
'ruleOperator' => 'like',
'ruleValues' => array('someemail@somecompany.com')
)
),
array(
'type' => 'rule',
'connector' => 'and', // Connector for the next rule
'rules' => array(
'ruleName' => 20, // Custom field ID
'ruleOperator' => 'like',
'ruleValues' => array('somename')
)
)
// ---
)
)
)
);
$status = $segment->Create();
if (!$status) {
print "Cannot create segment";
} else {
print "Segment created with the following id: {$segment->segmentid}";
}
Analysis of the code:(1) Include segment API
(3) Instantiate new Segment API
(5) Set up owner ID
(8) Specify current time (use AdjustTime() function to do this)
(11) Segment name
(14) Specify the segment search info
(17) Specify the list Ids 00 – These are arrays
(20) Specify the rules
The following rules apply:
- Rule Type can either be: “group” or “rule”
- Rule Connector can either be: “and” or “or”
-
“ruleName”: is the fields that the rule will be applied to... This can either be a special fields, or a custom field ID. Currently available special fields are:
- email: Filter by email
- format: Filter by format (“h” or “t”)
- status: Filter by format (“b”, “u”, or “a” translate to “bounced”, “unsubscribed”, “active”)
- confirmation: Filter by conformation status (“1” or “0”)
- confirmation: Filter by conformation status (“1” or “0”)
- subscribe: Filter by subscribe data (mm/dd/yyyy)
- link: Filter by have/have not clicked a particular link (it accept a link id)
- campaign: Filter by have/have not opened a particular campaign (it accept a newsletterid)
- subscriberid: Filter by subscriber id
-
”ruleOperator” value will depends on the context of the “ruleName”, so not all of the following rules will be available for each “ruleName”
- equalto
- notequalto
- like
- notlike
- between
- greaterthan
- lessthan
3 Responses to "Creating segment from the API" 
|
said this on 24 Sep 2008 11:08:08 AM CST
thanks a lot for this information... this is great tutorial .. hope you can get more of this soon
|
|
said this on 24 Sep 2008 12:01:41 PM CST
you have an error in line 34 you forgot a ':
'ruleValues' ; => array('someemail@som ecompany.com') // this is the good one. |
|
said this on 25 Sep 2008 7:50:16 PM CST
Yup, I will update the example
|

Author/Admin)