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.

PHP Wrapper: Delete user by email address

Highlighted
Occasional Contributor

PHP Wrapper: Delete user by email address

I'm trying to delete a user by email address using the PHP wrapper and I am having trouble.  I think I'm close.  Here is what I have so far:

 

$ConstantContact = new ConstantContact("basic", "apikey", "usr", "pwd");
// Search for a contact by Email Address
$search = $ConstantContact->searchContactsByEmail('test@test.com');
// Get details for the Contact
$Contact = $ConstantContact->getContactDetails($search[0]);	
// Delete the contact returned above
$delete = $ConstantContact->deleteContact(***what goes here?***);

I'm having trouble figuring out what goes in the last line to actually delete (unsubscribe) the user?

 

On this subject, I know there are some very basic examples here but there isn't a whole lot of documentation overall that I'm seeing, and the examples are kind of limited in scope.  Is it somewhere else that I'm missing?  Thanks!

1 REPLY 1
Highlighted
Employee

Re: PHP Wrapper: Delete user by email address

Hey Jeff,

 

In the wrapper itself there is some documentation which willt ell you what you need.

    /**
     * Delete a contact
     * @param Contact $Contact - Contact
     * @return bool
     */
    public function deleteContact(Contact $Contact){
        $ContactsCollection = new ContactsCollection($this->CTCTRequest);
        return $ContactsCollection->deleteContact($this->CTCTRequest->baseUri.$Contact->link);
    }

What you want to do is pass it a Contact Object.  When you do the searchContactsByEmail it will give you back an array of objects. Thats why when you use [0] it will grab the first (in this case the only) object that is returned. 

 

	$SearchContact = $ConstantContact->searchContactsByEmail('test@test.com');
	$DeleteContact = $ConstantContact->deleteContact($SearchContact[0]);

Please let me know if this fixes your issue.

Ryan Davis
Quality Engineer
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