views:

106

answers:

2

Using the CampaignMonitor API, I am able to subscribe, resubscribe and unsubscribe successfully, but I can't figure out how check if an email address is active, or unsubscribed. The end goal, is basically if subscribed, echo an unsubscribe link, if not subscribed echo a subscribe link.

After digging around CMBase it appears that subscribersGetIsSubscribed() is what I need to target. I've successfully been able to tap into the function and get the proper true/false response when I echo $cm->debug_response. However, when I apply that into an if/else statement it doesn't work properly.

Example:

$result = $cm->subscribersGetIsSubscribed('[email protected]'); if ($cm->debug_response == "True") { echo "active"; } else { echo "not subscribed";}

A: 

What is the if/else statement you're attempting? Based on the documentation, it looks like this should work:

$result = $cm->subscribersGetIsSubscribed('[email protected]');
if ($result == 'True') {
    echo 'active';
} else {
    echo 'not subscribed';
}

(Note that "True" is there a string literal, and not, as one would perhaps imagine, the true boolean value.)

VoteyDisciple
Thanks for your answer. The result returned is an array, not a string. I found out that the array key that holds the value is 'anyType'. Thanks again for your efforts :)
mikemick
A: 

Someone in the CampaignMonitor forum answered, here is the result, which works properly...

$result = $cm->subscribersGetIsSubscribed('[email protected]',$list_id);

if ($result['anyType'] == "True") { echo "active"; } else { echo "not subscribed";}
mikemick