The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

What is the preferred method of handling duplicate contact errors?

Highlighted
Occasional Contributor

What is the preferred method of handling duplicate contact errors?

What is the preferred method of handling "duplicate contact" errors?

 

My code:

 

 

session_start ();
require_once 'ccontact/ConstantContact.php';
require_once 'ccontact/config.php';
        
$ConstantContact = new ConstantContact ( "oauth2", $apikey, $username, $accessToken );

$ContactLists = $ConstantContact->getLists();

// echo print_r($ContactLists);




    if(isset($_POST['emailaddress'])){
    

    
            $Contact = new Contact();
            $Contact->emailAddress = $_POST['emailaddress'];
            $Contact->firstName = $_POST['firstname'];
            $Contact->lastName = $_POST['lastname'];
            $Contact->lists = $_POST['lists'];
            $NewContact = $ConstantContact->addContact($Contact);
            if($NewContact){
                echo "<script>alert('Congrats!  You are added to the mailing list.');</script>";
    
            }
        

        
        
        
    }

 

 

RIght now, this gets placed within the markup of my page, and I'd like to hide it and replace it with a nicer error message to the user:

 

Constant Contact HTTP Request Exception: Error 409: Email address _(myemail)_ is already a contact

Fatal error: Call to a member function Attributes() on a non-object in /data/14/1/78/53/1078053/user/1118909/htdocs/ccontact/Components.php on line 208

1 REPLY 1
Highlighted
Employee

Re: What is the preferred method of handling duplicate contact errors?

Hi,

 

If you look a tthe sample code I posted on your other forum post here, I first search to see if the email address exists, then I add  a new contact if it doesn't, and update the existing contact if it does already exist in the account.  That's my preference.  However, you could also check to see if they exist (like I do), and then not update them and echo that they are already subscribed.

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured