Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Adds Email Multiple Times Duplicated #20

Closed
rayliverified opened this issue Dec 22, 2017 · 6 comments
Closed

API Adds Email Multiple Times Duplicated #20

rayliverified opened this issue Dec 22, 2017 · 6 comments

Comments

@rayliverified
Copy link

rayliverified commented Dec 22, 2017

The MailWizz API adds the same email multiple times.
maxthonsnap20171222132457

This is my code for adding an email:
//MailWizz require_once dirname(__FILE__) . '/mailwizz.init.php'; $endpoint = new MailWizzApi_Endpoint_ListSubscribers(); //App New Users $response = $endpoint->create('wj730zl99w094', array( 'EMAIL' => $email ));

Doesn't MailWizz automatically check if a subscriber is already added and if so, not add that subscriber again?

@twisted1919
Copy link
Owner

Do you have any email verification service enabled ?

@rayliverified
Copy link
Author

No.

I did some more testing and I believe I have isolated the reason for the problem.
I am calling the MailWizz API in a POST request and for some reason, the POST request is executed multiple times. The POST request is only called once, but the server executes it multiple times which is why the MailWizz API is adding the same email multiple times. When the MailWizz request is removed from the POST request, the POST request only executes once.

I do not know why MailWizz would cause a POST request to repeat. This seems like a separate issue.

The issue here is that MailWizz adds an email even when it already exists.

My post request:

<?php
if (!empty($_POST)) {

    $email = isset($_POST['email']) ? $_POST['email'] : '';

    $email = helper::clearText($email);
    $email = helper::escapeText($email);

    $result = array();
    $result = $helper->isEmailExistsInfo($email);

    if ($result['error'] !== false)
    {
        //MailWizz
        require_once dirname(__FILE__) . '/mailwizz.init.php';
        $endpoint = new MailWizzApi_Endpoint_ListSubscribers();
        //Delete user if exists in list so user can be added again.
        $endpoint->deleteByEmail('wj730zl99w074', $email);
        //App New Users
        $response = $endpoint->create('wj730zl99w074', array(
            'EMAIL'    => $email
        ));
    }

    echo json_encode($result);
    exit;
}

@twisted1919
Copy link
Owner

Maybe you should use createUpdate instead of create and don't call deleteByEmail anymore, so try that and see how it goes.

On another note, Mailwizz does check for dupes, but somehow your request is multiplied at the same time and therefore is too fast for mailwizz to catch it for some reason, i assume mainly because the database check for dupes takes too long. You might wanna look at https://kb.mailwizz.com/articles/performance-improvements/ or try to see why the post request gets multiplied, as mailwizz doesn't do this.

@rayliverified
Copy link
Author

I did some more research and it looks like 90% of the issue is because my client is retrying the POST request due to timeout which is why the POST request is being called multiple times. However, the max number of retries is 1 which means at most, the email should only be added twice.

There are instances where emails have been added 3 times. Could the internal HttpClient used by MailWizz have a retry timeout too? See this StackOverflow for a description of the default behavior of HttpClient: https://stackoverflow.com/questions/23054289/httpclient-executes-requests-multiple-time-if-request-timed-out

Thanks for the help!

@twisted1919
Copy link
Owner

The client we're using in the code does not do any retry.

@rayliverified
Copy link
Author

Ok, good to know. I think I've solved the issue by setting retry to 0 in the client. If I get anymore duplicates, I'll reopen this issue for further investigation. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants