mailjet / mailjet-apiv3-php-simple

[API v3] Simple PHP wrapper for the Mailjet API /!\ [DEPRECATED - SEE README] /!\
https://dev.mailjet.com
MIT License
55 stars 45 forks source link

Getting alle unsubscribed contacts of list #53

Closed wfabian closed 9 years ago

wfabian commented 9 years ago

Hi, I like to get all unsubscribed contacts of a list.

I tried something like this: function mailjetGetUnsubscribedContactsFromList(Mailjet $mj, $listID) { $params = array( "method" => "GET", "ListID" => $listID, "IsUnsubscribed" => true ); $result = $mj->listrecipient($params); if ($mj->_response_code == 201) return "Okay"; else echo "error - ".$mj->_response_code; }

But the contact-ID is for listrecipient-function mandatory, too. Is there anyway to solve my problem?

hristo-todorov commented 9 years ago

Hi @wfabian,

In order to get a list of all unsubscribed contacts of a list you need to filter the contact list. Here's a code snippet that does this:

function getUnsubscribedContactsFromList(Mailjet $mj, $listID) {
    $params = array(
        "method" => "GET",
        "ContactsList" => $listID,
        "Unsub" => true
    );

    $result = $mj->listrecipient($params);

    if ($mj->_response_code == 200)
       echo "success - got unsubscribed contact(s) ";
    else
       echo "error - ".$mj->_response_code;

    return $result;   
}

I hope this helps. Don't hesitate to contact me if you need more help,

This code snippet and more could be found at https://github.com/mailjet/mailjet-apiv3-php-simple/blob/master/README.md

For more contact list filters you can have a look at our reference guide - http://dev.mailjet.com/email-api/v3/listrecipient/#filters

Cheers!

wfabian commented 9 years ago

Thank's again, that solved my problem.

WeshGuillaume commented 9 years ago

Hey @wfabian :airplane:

We just released a new PHP API wrapper. It is now more PHP-ish (including namespace, PSR-0 compliance, and globally a better architecture). All it requires is PHP 5.4

In addition to our API Guides, we would be happy to help you get started with it.

Guillaume, from Mailjet!