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.

Add contact to multiple lists

Highlighted
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
Highlighted
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

Highlighted
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

Highlighted
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

Highlighted
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;

  }

 

}

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