How to PREVENT subscribing to a list?

MauriceW

Member
I use Everwebinar to host a webinar with a sales pitch at the end. To get people from Everwebinar into MailWizz I use ActiveCampaign,

ActiveCampaign works as a bridge between EverWebinar and MailWizz. I do it this way, because there is no direct integration between EverWebinar and MaiWizz. (I wish there was)

Now Everwebinar sends different status updates to ActiveCampaign. For example:

- Registered
- Attended
- Leave
- Replay

Based on the status, ActiveCampaign sends a webhook to an external PHP script that uses the MailWizz API to subscribe the contact to the corresponding list.

Now the problem:

The thing is that EverWebinar has a pretty big delay between when something happens and when they send the update to ActiveCampaign.
When they leave the webinar before the sales pitch, Evewebinar updates the contact in ActiveCampaign an dtags them 'LEAVE'.

Then ActiveCampaign sends a webhook to MailWizz and the contact is added to the MailWIzz list 'Leave'.

However, when someone buys at the end of the webinar, they are subscribed to the MailWizz list 'Purchased'.
This is a direct WooCommerce -> MailWizz integration.

Then, becasue of the lag, after a few hours, EverWebinar sends the contact to ActiveCampaign, and then subscribes the contact to the list 'Attended' (for example).

This is too late.

The contact is already in the list 'Purchased' and should NOT be subscribed to the list 'Webinar Attended'.

So the question is:
How can I prevent a contact being subscribed to certain lists when they are already subscribed to the list 'Purchased'?

Thanks,
Maurice
 
Well, the API has an endpoint which allows you to check if a subscriber belongs to a certain list, so you could use that to check first if the subscriber is in a certain list, and if not add it to whatever list you need.
 
Well, the API has an endpoint which allows you to check if a subscriber belongs to a certain list, so you could use that to check first if the subscriber is in a certain list, and if not add it to whatever list you need.
Ah, that sounds like a plan! Thank you. Awesome..

Do you have a PHP example somewhere how to check if a contact is subscribed to a certain list?
 
Thanks, that looks good. I tried it, but it returns an error:

EmsApi\Params Object
(
[_data:EmsApi\Params:private] => Array
(
[status] => error
[error] => Page not found.
)

[_readOnly:EmsApi\Params:private] =>
)

I see that the editor changes some text into emoji's. So I attached a screenshot of the error.
 

Attachments

  • Screenshot_1.png
    Screenshot_1.png
    4.8 KB · Views: 4
This code works:
$response = $endpoint->getSubscribers($list_unique_id, $pageNumber = 1, $perPage = 10);

This one works too:
$response = $endpoint->emailSearch($list_unique_id, $email);

However they both return values that I cannot use. I just tried them to see if the API itself is working.
This confirms it is.

And this is actually the one I need (as you suggested):
$response = $endpoint->getSubscriber($list_unique_id, $email);

But that one returns the error above...
 
And this is actually the one I need (as you suggested):
$response = $endpoint->getSubscriber($list_unique_id, $email);
This is not what I suggested, but this:
This one works too:
$response = $endpoint->emailSearch($list_unique_id, $email);


However they both return values that I cannot use.
They return the subscriber with its status, what exactly do you need?
Since this returns the subscriber with it's uid, if you need more info about that subscriber, you can issue a second api call using:
$endpoint->getSubscriber($list_unique_id, $subscriber_unique_id);
Since now you know the subscriber unique id.
 
There is something strange going on with the API, because it does not return the subscriber.

Instead it ADDS the email address to another list.

There is no reference to this other list in this script.

So I paste the full code below.

I search the list with ID go66***2as9c2, but then this email address is subscribed to list with ID dj066***skc7c.

So no matter which email I search for, it always returns a success message, even if the email address is not in the system.

What am I doing wrong here?


$config = new \EmsApi\Config([
'apiUrl' => 'https://mailwizz.mydomain.net/api/index.php',
'apiKey' => '************************************************'
]);

\EmsApi\Base::setConfig($config);

$endpoint = new EmsApi\Endpoint\ListSubscribers();
$list_unique_id = 'go66***2as9c2';
$response = $endpoint->emailSearch($list_unique_id, $email);

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
 
Last edited:
The emailSearch method is described at https://github.com/ems-api/php-client/blob/master/src/Endpoint/ListSubscribers.php#L274 and if you take a look it calls a URL like: lists/[LIST_UID]/subscribers/search-by-email.
If we look in the code for this endpoint, it is defined in /apps/api/controllers/List_subscribersController.php at line 1135:
PHP:
public function actionSearch_by_email($list_uid)
    {
        $email = request()->getQuery('EMAIL');
        if (empty($email)) {
            $this->renderJson([
                'status'    => 'error',
                'error'     => t('api', 'Please provide the subscriber email address.'),
            ], 422);
            return;
        }

        $validator = new CEmailValidator();
        $validator->allowEmpty  = false;
        $validator->validateIDN = true;
        if (!$validator->validateValue($email)) {
            $this->renderJson([
                'status'    => 'error',
                'error'     => t('api', 'Please provide a valid email address.'),
            ], 422);
            return;
        }

        /** @var Lists|null $list */
        $list = $this->loadListByUid($list_uid);

        if (empty($list)) {
            $this->renderJson([
                'status'    => 'error',
                'error'     => t('api', 'The subscribers list does not exist.'),
            ], 404);
            return;
        }

        /** @var ListSubscriber|null $subscriber */
        $subscriber = ListSubscriber::model()->findByAttributes([
            'list_id'   => (int)$list->list_id,
            'email'     => $email,
        ]);

        if (empty($subscriber)) {
            $this->renderJson([
                'status'    => 'error',
                'error'     => t('api', 'The subscriber does not exist in this list.'),
            ], 404);
            return;
        }

        $this->renderJson([
            'status'    => 'success',
            'data'      => $subscriber->getAttributes(['subscriber_uid', 'status', 'date_added']),
        ]);
    }
And as you can see above, there's no code in place to actually add a subscriber, it just does a search.

The addition happens from your code, so check that.
 
Back
Top