We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Using the Bulk Activities Service class

MatthewM8435
Occasional Participant

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
Elijah_G
Member

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
MatthewM8435
Occasional Participant

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