PHP API returning malformed array for Subscribers.GetActive

Hi all,

I'm using the latest version of the Campaign Monitor PHP kit located at to access & update my subscriber data. When I make a call to the Subscribers.GetActive method (via $myInstance->subscribersGetActive() in my PHP), I get an array of data back, but the Custom Field data is not formatted as I would expect. When I var_dump() the result from the method call, I get the data seen here:

Our list has two custom fields: "Time Zone" and "Group." The result shown above is a subset of the array that the API call returns (after the api kit runs the xml2array() function on the raw XML result). Here are three observations that I've made about the incorrectly-parsed XML:

1. The first subscriber returned (index zero in the array of 3864 results) is correct. Note that the SubscriberCustomField array has two key/value pairs, one for each of my custom fields. This is what I would expect. All other subscriber entries have malformed custom field data.

2. Starting with the second subscriber in the Pastie link, there are 2 SubscriberCustomField elements for each subscriber: the first one has just a key, with the associated value found in the next SubscriberCustomField element. I believe this is incorrect, and it happens for every result after the first.

3. Looking closely at the 'CustomFields' element of each subscriber result, you'll see that the extra CustomFields array described in #2 has an index that corresponds with the index of the subscriber we're looking at. To illustrate, look at the last subscriber in the Pastie link (index 31). The CustomFields array has two elements: index zero and index 31. Another observation I made about the array indices is with the second SubscriberCustomField element for each subscriber. In that array, the second element has an index that appears to follow the pattern 2*N + 1, where N is the index of the subscriber you're looking at. For instance, in subscriber index 31 in the Pastie link, the second element of the second SubscriberCustomField has an index of 63, which is 2*31 + 1.

I hope these observations prove useful to someone. I'm not entirely clear how the XML Parser functions work in PHP, so I'm not in a position (yet) to do any useful code debugging or patches with the api kit itself.


whitespace, 7 years ago

I have this problem too. 
I cannot throw any more light on it just now though.


whitespace, 7 years ago

This issue can be fixed by inserting this code between lines 695 and 696 of CMBase.php.

I would stress that this is not fully tested, and there is probably a more efficient way, but this seems to do the trick for me.


//clean stack_count array: reset any paths below this level
                    $this_path = $this->stack_prefix.$partial;
                    $this_length = strlen($this_path);
                    $this_level = count( explode('/', $this_path ) );
                    foreach( $this->stack_count as $sk => $s ) {
                        if( substr($sk, 0, $this_length) == $this_path && $this_level < count( explode('/', $sk ) ) ) {
                            $this->stack_count[$sk] = 0;
sowsinsk, 7 years ago

Your solution appears to work for me. Thanks!
- Steve

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free