0

I want to create a subgroup that is a subgroup, using API v3, and I'm not sure how to set the condition in the request. For some reason I can't get to the Playground today, so I can't play with it.

I'm thinking something like:

function createSegment($apikey, $dc, $list_id, $name) {
    $data = array(
        "name"=> $name,
        **CONDITION**
    );
    $data = json_encode($data); // API requires JSON objects
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "http://".$dc.".api.mailchimp.com/3.0/lists/".$list_id."/segments"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, true); // declare request is POST type
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set POST data
    curl_setopt($ch, CURLOPT_USERPWD, "user:".$apikey); // HTML Basic Auth
    $output = curl_exec($ch); // execute and capture response
    curl_close($ch); 
}
ekad
  • 14,436
  • 26
  • 44
  • 46
ivanacorovic
  • 2,669
  • 4
  • 30
  • 46

1 Answers1

0

This is what the API Support had to say:

With the release of version 3.0 of our API we made some changes to the structure of how we use IDs. In this case there are currently 2 sets of IDs that groups can be referenced by, depending on which version of the API you are using.

In version 2.0, the group ID is an integer and can be retrieved using the /lists/interest-groupings call here:

https://apidocs.mailchimp.com/api/2.0/lists/interest-groupings.php

With version 3.0, the group ID is a hash and is returned by making a GET request to the Lists Interest Collection endpoint here:

http://kb.mailchimp.com/api/resources/lists/interest-categories/interests/lists-interests-collection

When creating a segment however, we currently only accept the group ID returned in version 2.0 of the API, regardless of whether that segment call is being made with 2.0 or 3.0. For this reason, when segmenting by groups, a call would need to be made to the 2.0 endpoint to retrieve those groups IDs. These IDs are static though, so if they are expected to be updated, they would only need to be requested once and can then be stored locally.

ivanacorovic
  • 2,669
  • 4
  • 30
  • 46