Pregunta

Does anyone know if there is a way of checking a subscribers status on a list.

The only way I can see to do it is loop through the active and unsubscribed subscribers on a list and see if it matches. Obviously this is not very efficient if there are 10's of thousands of subscribers.

What I'm trying to do is have a form on a site that allows you to unsubscribe or subscribe to a mailing list. I'd like this to check Campaign Monitor to see which lists they are subscribed to and precheck those boxes.

¿Fue útil?

Solución

Use Client.ListsForEmail to get all the lists for a given email address, and then once you have the lists you should be able to check the status of the subscriber in each of those

Otros consejos

You can do it like that -- checking if the subscriber exists in a list -- but it's easier to do it the other way, by checking if a list has a given subscriber. Like this:

function is_subscribed_to_list($list_id, $email_address) {
    require_once('createsend-php/csrest_lists.php');
    $auth = array('api_key'=>$this->api_key);
    $wrap = new CS_REST_Clients($client_id, $auth);
    $result = $wrap->get_lists_for_email($email_address);
    $list_subscriptions = (array) $result->response;
    return array_key_exists($list_id, $list_subscriptions);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top