cancel
Showing results for 
Search instead for 
Did you mean: 

php wrapper - updateContact

tkc
New Member

php wrapper - updateContact

 

function updateContact($newmember){
//Create search object and search cc lists for user 
  	   $contacts = new ContactsCollection();
  		$search = $contacts->searchByEmail($newmember['email']);


//Get resources of contact we found
	
	$contactId = $search[0][0]->getId();
	     
	     		$contact = new Contact();
	     		$contact->setId($contactId);
	     		$contact->setLink($search[0][0]->getLink());
	 		   $contact->setEmailAddress($newmember['name_f']);
				$contact->setFirstName($newmember['name_l']);
				$contact->setLastName($newmember['street']);
				$contact->setAddr1($newmember['city']);
  				$contact->setCity($newmember['state']);
  				$contact->setStateCode($newmember['zip']);
  				$contact->setCountryCode($newmember['country']);
  				$contact->setPostalCode($newmember['email']);
	  
	   
	  
			//Sadly we must get all lists from account
				$myLists = new ListsCollection();
				$lists = $myLists->getLists();
			//Loop through them
				foreach($lists[0] as $list){
					$name = $list->getName();
				//Find the Correct list	
					if($name == 'ifp members'){
					//Get lists ID and assign it to our contact
					$id = $list->getId();
					$contact->setLists($id);					
					}
				}
				
//Create Collection object and send update request 	
 	$collection = new ContactsCollection();
 	$return = $collection->updateContact($contactId,$contact);
 
	 echo $return;
}

 

 

ok so this code is a bit messy, but I can't quite seem to get the updateContact function to work. This returns a 400. What are the requirements for a proper contact object to pass to the updateContact function? 

 

Any comments appreciated! 

 

Thanks,

tk

1 REPLY 1
CTCT Employee

Re: php wrapper - updateContact

Hello,

 

I took a look at your code and I believe I found the issue.  Our system will return a 400 error if the XML that is included in the https call has data in certain nodes that it knows is not correct.  This includes StateCode, CountryCode, and PostalCode.  I see that in your code you are using setPostalCode as the email and setStateCode as the zip code.  If you change these calls to point to the correct data, it should allow the update to work.

 

If you are still running into an issue please let me know and we will continue to troubleshoot to find out what is going on.

 

Regards,

 

Ben Soder

API Support

Benjamin Soder
NOC Analyst
Constant Contact