cancel
Showing results for 
Search instead for 
Did you mean: 

Add contact to multiple lists

Occasional Contributor

Add contact to multiple lists

I can't find anywhere in the API documentation that describes how to add a contact to multiple lists.  What would be the procedure for that?

 

Thanks,

 

Matthew

4 REPLIES 4
CTCT Employee

Re: Add contact to multiple lists

Hi Matthew,

 

The raw JSON you submit would have a lists section like this:

 

"lists": [
{
"id": "1"
},
{
"id":"18"
}
],

 

If you're using our newest PHP wrapper, you could follow the example here, which gives the user the ability to select any lists they want, or your code to add multiple lists to your contact object could look something like this:

 

$contact->addList("1");
$contact->addList("18");

 

I'll try to have our documentation updated to show more than one list; thanks for the feedback.

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Contributor

Re: Add contact to multiple lists

Thanks for that - I didn't realize addList could be used more than once for a single request. (I've read so much documentation on multiple versions of the SDK and API that it's all starting to run together.)

 

So when updating a contact in the current version of the SDK, is it still necessary to check which lists the email address is already on, and include them in the update as well?

 

Thanks again,

 

Matthew

CTCT Employee

Re: Add contact to multiple lists

HI Matthew,

 

When you do a getContactDetails in the php sdk, the lists a contact is already on is included.  The addList function does add to the lists array, so you shouldn't need to include all of the lists you want the contact to be on, just the ones that are being added.

 

If you were to specify the lists array for a contact instead of using the addList function, you would need to specify all lists.

 

Best Regards,

Shannon W.

API Support Specialist

Regular Visitor

Re: Add contact to multiple lists

I needed to create a user and assign multiple lists

 

I took the Shannon_W's idea and I made this.

 

class className(){

 

  public $AccessToken = 'here your Access Token';

  public $ApiKey = 'here your api key';

 

  function addContact($ObjMember){

     $cc = new ConstantContact($this->ApiKey);

     $Lists = array('1','2','3','4'); //can be more or less lists

     .......

     $Contact = new Contact();

     $Contact->first_name = $ObjMember->name_f;
     $Contact->last_name = $ObjMember->name_l;

     .......

     foreach ($Lists as $row):
          $Contact->addList($row);
     endforeach;

     ......

     $data = $cc->addContact($this->AccessToken, $Contact, false);

 

     return $data;

  }

 

}