Adding existing user to a list

SOLVED
Visitor

Adding existing user to a list

I'm using the library from https://github.com/ctctsupport/ctct_php_library.

I am trying to set up a batch import of contacts, but if the contact already exists, then I just need to check if already is on the list or add it to the list.

 

$collection=$CC->searchContactsByEmail($email); 

 When I do a var_dump on an existing contact I get something like:

array
  0 => 
    object(Contact)[8]
      public 'link' => string '/ws/customers/[removed]/contacts/1' (length=34)
      public 'id' => string 'http://api.constantcontact.com/ws/customers/[removed]/contacts/1' (length=64)
      public 'updated' => string '2012-05-24T20:32:03.965Z' (length=24)
      public 'status' => string 'Active' (length=6)
      public 'emailAddress' => string '[removed]' (length=20)
      public 'emailType' => string 'HTML' (length=4)
      public 'firstName' => string '' (length=0)
      public 'middleName' => string '' (length=0)
      public 'lastName' => string '' (length=0)
      public 'fullName' => string '' (length=0)
      public 'jobTitle' => string '' (length=0)
      public 'companyName' => string '' (length=0)
      public 'homePhone' => string '' (length=0)
      public 'workPhone' => string '' (length=0)
      public 'addr1' => string '' (length=0)
      public 'addr2' => string '' (length=0)
      public 'addr3' => string '' (length=0)
      public 'city' => string '' (length=0)
      public 'stateCode' => string '' (length=0)
      public 'stateName' => string '' (length=0)
      public 'countryCode' => string '' (length=0)
      public 'countryName' => string '' (length=0)
      public 'postalCode' => string '' (length=0)
      public 'subPostalCode' => string '' (length=0)
      public 'notes' => string '' (length=0)
      public 'customField1' => string '' (length=0)
      public 'customField2' => string '' (length=0)
      public 'customField3' => string '' (length=0)
      public 'customField4' => string '' (length=0)
      public 'customField5' => string '' (length=0)
      public 'customField6' => string '' (length=0)
      public 'customField7' => string '' (length=0)
      public 'customField8' => string '' (length=0)
      public 'customField9' => string '' (length=0)
      public 'customField10' => string '' (length=0)
      public 'customField11' => string '' (length=0)
      public 'customField12' => string '' (length=0)
      public 'customField13' => string '' (length=0)
      public 'customField14' => string '' (length=0)
      public 'customField15' => string '' (length=0)
      public 'contactLists' => string '' (length=0)
      public 'confirmed' => string '' (length=0)
      public 'optInSource' => string 'ACTION_BY_CUSTOMER' (length=18)
      public 'lists' => 
        array
          empty

 I am positive that this contact is already on several lists, but it does not show any lists in the array.  Why is the array empty?

 

After getting the contact collection I would like to do this:

$Contact=$collection[0];

// is this user already on this list?
if(!in_array($list,$Contact->lists)) { $Contact->lists[]=$list; var_dump($Contact); echo "adding user to list<br />"; echo $CC->updateContact($Contact); }
else {echo "user already in list."; }

 

Would that work?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Trusted Contributor

Re: Adding existing user to a list

Hello, 

 

The GET request made by the wrapper to search for a contact by email address returns only basic information about the contact (Status, EmailAddress, EmailType, Name, OptInTime, OptInSource, Confirmed, and InsertTime). To get the full details, including list memberships, you need to make a request on the specific contact resource, itself.

 

The flow would be:

1)     Determine if contact exists with a successful search for the contact by email address using function searchContactByEmail() in the wrapper,

2)     Request contact details to get list membership using the getContactDetails() function in the wrapper,

3)     Modify contact object as needed reflect desired new  list membership,

4)     Update using the updateContact() function.  

 

Keep in mind that the call to update contacts will replace the current details with those you provide in the update request body. so all lists the contact should be on after the update requests is executed should be included in your update request.

 

I hope this helps you. Let us know if you have any additional questions.

Mark Coleman
Support Engineer

View solution in original post

2 REPLIES 2
Highlighted
Trusted Contributor

Re: Adding existing user to a list

Hello, 

 

The GET request made by the wrapper to search for a contact by email address returns only basic information about the contact (Status, EmailAddress, EmailType, Name, OptInTime, OptInSource, Confirmed, and InsertTime). To get the full details, including list memberships, you need to make a request on the specific contact resource, itself.

 

The flow would be:

1)     Determine if contact exists with a successful search for the contact by email address using function searchContactByEmail() in the wrapper,

2)     Request contact details to get list membership using the getContactDetails() function in the wrapper,

3)     Modify contact object as needed reflect desired new  list membership,

4)     Update using the updateContact() function.  

 

Keep in mind that the call to update contacts will replace the current details with those you provide in the update request body. so all lists the contact should be on after the update requests is executed should be included in your update request.

 

I hope this helps you. Let us know if you have any additional questions.

Mark Coleman
Support Engineer

View solution in original post

Highlighted
Visitor

Re: Adding existing user to a list

Excellent, thanks Mark.

Developer Portal

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

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured