Between 8:00 - 9:00 am ET on 10/25 we need to take our site down to make updates. We recommend logging out before 8:00am ET and not using your account during this time. Thank you for your patience while we make these important updates.

How to assign bulk existed contacts to one list at a time using JAVA API

Occasional Participant

How to assign bulk existed contacts to one list at a time using JAVA API

Hello Team,

We are using Constant contact Java API for Conatct add/update and Contact List add/update .But its taking too much time for adding multiple contacts .

So is there any possiblility to add bulk conatcts in single api call .If possible please provide us JAVA code It will helpfull for us.

 

Thanks & Regards,

Harsha Chepana.

 

3 REPLIES 3
Moderator

Hello,

 

Thank you for reaching out to Constant Contact's API Support.

 

You can add contacts in a bulk activity. We have a JAVA library/wrapper created that has examples that would assist you with this. You can find the library in its entirety here (http://developer.constantcontact.com/libraries/libraries.html).

 

I have searched through the library and I have found a specific section that will assist in adding contacts in bulk. You can find that here (http://conta.cc/2bg6QPm).


Regards,
Jimmy D.
Tier II API Support Engineer
Occasional Participant

 

import com.constantcontact.components.activities.contacts.request.ContactData;
import com.constantcontact.components.activities.contacts.request.CustomField;
import com.constantcontact.components.activities.contacts.request.AddContactsRequest;
import com.constantcontact.components.contacts.ContactList;
import com.constantcontact.exceptions.component.ConstantContactComponentException;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.activities.BulkActivitiesService;
import com.constantcontact.components.activities.contacts.request.AddContactsRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author miracle
*/
public class BulkUpdate {

public static void uploadMembers(ArrayList alMemberId, ArrayList alFirstName,
ArrayList alLastName, ArrayList alEmailId
)
{
try {
BulkActivitiesService blk=new BulkActivitiesService("token", "api key");
// Create AddContactsRequest object
AddContactsRequest objAddContactsRequest = new AddContactsRequest();

// Create new list of contact data
List<ContactData> lsContactData = new ArrayList<ContactData>();

// Create list of columns
List<String> lsColumnName = new ArrayList<String>();

// Create object for contact list
List<String> contactlist = new ArrayList<String>();

// ContactList object
ContactList objContactList = new ContactList();


for(int i=0; i < alMemberId.size(); i++)
{
// Create new contact data object
ContactData objContactData = new ContactData();

// Set Email Id
List<String> lsEmailAddresses = new ArrayList<String>();
lsEmailAddresses.add(alEmailId.get(i).toString());
objContactData.setEmailAddresses(lsEmailAddresses);

// Set First Name
objContactData.setFirstName(alFirstName.get(i).toString());

// Set Last Name
objContactData.setLastName(alLastName.get(i).toString());

// Set Member Id
CustomField objCustomField = new CustomField();
List<CustomField> lsCustomField = new ArrayList<CustomField>();
objCustomField.setName("CUSTOMFIELD1");
objCustomField.setValue(alMemberId.get(i).toString());
lsCustomField.add(objCustomField);
objContactData.setCustomFields(lsCustomField);
//objContactData.setCustomFields(lsCustomField)
// Add contact to contact list
lsContactData.add(objContactData);

} // End of for

lsColumnName.add("EmailAddresses");
lsColumnName.add("FirstName");
lsColumnName.add("LastName");
lsColumnName.add("CUSTOMFIELD1");

// Set List id
objContactList.setName("bulKList");
objContactList.setStatus("Active");
contactlist.add(objContactList.toString());

// Set list name for upload
objAddContactsRequest.setLists(contactlist);
objAddContactsRequest.setImportData(lsContactData);
// Set column names
objAddContactsRequest.setColumnNames(lsColumnName);

// Import data into AddContactsRequest


System.out.println(objAddContactsRequest.toJSON());
blk.addContacts(objAddContactsRequest);
} catch (ConstantContactComponentException ex) {
Logger.getLogger(BulkUpdate.class.getName()).log(Level.SEVERE, null, ex);
} catch (ConstantContactServiceException ex) {
Logger.getLogger(BulkUpdate.class.getName()).log(Level.SEVERE, null, ex);
}


}
public static void main(String[] args) {


ArrayList alMemberId = new ArrayList();
ArrayList alFirstName = new ArrayList();
ArrayList alLastName = new ArrayList();
ArrayList alEmailId = new ArrayList();

alMemberId.add("1000");
alFirstName.add("ABCD");
alLastName.add("EFGH");
alEmailId.add("abcdefgh@gmail.com");

alMemberId.add("2000");
alFirstName.add("PQRS");
alLastName.add("TUVW");
alEmailId.add("pwer238@yahoo.com");

alMemberId.add("3000");
alFirstName.add("PERIWE");
alLastName.add("SDFKSD");
alEmailId.add("wierj@hotmail.com");

uploadMembers(alMemberId, alFirstName, alLastName, alEmailId);


}


}

 

 

 

 

 

 

 

 

 

 

Hello,

 

In another post (https://community.constantcontact.com/t5/Developer-Support-ask-questions/How-to-assign-bulk-conatcts...) you had requested a sample of code for using the Bulk Activity for adding multiple contacts in a single call.

 

I would recommend reviewing the sample code in this thread here: https://community.constantcontact.com/t5/Developer-Support-ask-questions/add-contacts-in-bulk/m-p/28...

 

Please feel free to reply here with any other questions you might have.

 

Sincerely,

David B.

API Support Specialist

Developer Portal

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

Visit Page