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.

Using the Bulk Activities Service class

Highlighted
Occasional Contributor

Using the Bulk Activities Service class

Hello,

 

I've been working with the Constant Contact API and I'm trying to get a bulk import class to work specifically, AddContactsRequest.java. My issue comes when I'm trying to make the class work. I dont understand how I'm supposed to run the methods. If any can help me out I would apreciate it!

 

Thank you!

2 REPLIES 2
Highlighted
Honored Contributor

Re: Using the Bulk Activities Service class

Hello,

 

Here is a very basic sample of how you could create a bulk activity using the most recent version of our Java SDK:

            BulkActivitiesService activitiesService = new BulkActivitiesService(accessToken,apiKey);            
            List<ContactData> importData = new ArrayList<ContactData>();
            ContactData cd;
            CustomField cf1;
            CustomField cf2;
            File theFile;

            cd = new ContactData();
            cd.setEmailAddresses(Arrays.asList("testThis2001z@yahoo.com"));
            cd.setFirstName("Tom");
            cd.setLastName("Jones");
            cf1 = new CustomField();
            cf1.setName("custom field 1");
            cf1.setValue("role1x role2x");
            cf2 = new CustomField();
            cf2.setName("custom field 2");
            cf2.setValue("role3x role4x");
            cd.setCustomFields(Arrays.asList(cf1, cf2) );
            importData.add(cd);
          
            AddContactsRequest request = new AddContactsRequest();
            request.setLists(Arrays.asList(listId));
            request.setColumnNames(Arrays.asList("EMAIL", "FIRST NAME", "LAST NAME", "CUSTOM FIELD 1", "CUSTOM FIELD 2"));
            request.setImportData(importData);
          ContactsResponse response = activitiesService.addContacts(request);

If you have any questions about the above code, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: Using the Bulk Activities Service class

Elijah,

 

Thank you for your help! Would this code be in a main method? Also for theFile how would I enter the file I would like to upload? My complier is telling me it won't accept a string value. 

 

Thanks again for everything!

 

Matthew

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