Sample Java Application

SOLVED
Go to solution
Regular Participant

Sample Java Application

Hi,

 

I am brand new to constantcontact.com and am looking for a sample application in Java that I can pick apart.

 

I am not very familiar with using github or other source code repositories. 

 

Is there any way to find a simple Java desktop application that will show me how to do authentication, basic CRUD for contacts and email campaigns?  If there any consultants reading this and wouldn't mind spending a few billable hours helping me get started I would be very interested in chatting with you.

 

Thanks in advance for any help!

1 ACCEPTED SOLUTION

Hello,

 

I've spent a decent bit of time contemplating this, and the best solution to your situation would be to do the following:

 

1. Download the source code of the SDK from https://github.com/constantcontact/java-sdk

2. Use maven from the command line (or from your IDE) to build the SDK. This will produce a standalone JAR file that will include the required dependencies.

3. Include the JAR file in your project so that you can use the SDK.

 

Within the SDK, you'll be looking to use the following services to accomplish your objectives:

You can access these services using the ConstantContactFactory class documented here: http://constantcontact.github.io/java-sdk/com/constantcontact/ConstantContactFactory.html

 

Here's a quick sample of setting up the factory and getting the ContactListService to create a list:

String accessToken="TOKEN", apiKey="KEY";
ContactList newList = new ContactList();

ConstantContactFactory _factory = new ConstantContactFactory(accessToken,apiKey);
ContactListService _listService = _factory.createContactListService();

newList.setName("Test List");
newList.setStatus("ACTIVE");
_listService.AddList(newList)

Once you've got the list created (or you can use the getLists method of the service to get the ID for an existing list), you can use the bulk service and the AddContactsRequest class to get the contacts imported.

 

Please feel free to reach out when you have questions along the way and I'll be happy to do what I can to help!

 

Sincerely,

 

Elijah G.
API Support Engineer

View solution in original post

9 REPLIES 9
Member

Hello,

 

Unfortunately Constant Contact does not have any first-party code that includes samples for a desktop app in Java. We do however have a java library for working with our API that includes Android code samples and some very basic setup instructions. You can either download the source for the library and build it yourself, or you can use Maven to include it in your project.

 

You can directly download the source, as well as find Maven instructions here:

https://github.com/constantcontact/java-sdk

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer

Thanks for the response.  I found everything you mentioned.  Unfortunately, while I know Java and have written a number of web services and basic applications, I do not use Maven, nor do I know how to get started with the API for a desktop application.

 

Surely, someone has a basic desktop application that integrates with your API.  I suspect a develope of the api has written some code for testing purposes.  Isn't there anyway to see one basic appilciation? 

 

I need to do the following:

Login from my server to constantcontact

Create a list of contacts

Create an email campaign

Send that campaign to the list of contacts

Get results of that email campaign

 

I can figure out most of the code I suspect from the doc, but I'm not sure how to start.  What the main would look like, what jar files are needed etc.  I would greatly appreciate some sort of helping hand to get started.

Hello,

 

I've spent a decent bit of time contemplating this, and the best solution to your situation would be to do the following:

 

1. Download the source code of the SDK from https://github.com/constantcontact/java-sdk

2. Use maven from the command line (or from your IDE) to build the SDK. This will produce a standalone JAR file that will include the required dependencies.

3. Include the JAR file in your project so that you can use the SDK.

 

Within the SDK, you'll be looking to use the following services to accomplish your objectives:

You can access these services using the ConstantContactFactory class documented here: http://constantcontact.github.io/java-sdk/com/constantcontact/ConstantContactFactory.html

 

Here's a quick sample of setting up the factory and getting the ContactListService to create a list:

String accessToken="TOKEN", apiKey="KEY";
ContactList newList = new ContactList();

ConstantContactFactory _factory = new ConstantContactFactory(accessToken,apiKey);
ContactListService _listService = _factory.createContactListService();

newList.setName("Test List");
newList.setStatus("ACTIVE");
_listService.AddList(newList)

Once you've got the list created (or you can use the getLists method of the service to get the ID for an existing list), you can use the bulk service and the AddContactsRequest class to get the contacts imported.

 

Please feel free to reach out when you have questions along the way and I'll be happy to do what I can to help!

 

Sincerely,

 

Elijah G.
API Support Engineer

View solution in original post

Elijah, THANK YOU SO MUCH!

 

That is what I needed to get started.  I finally have a shell put together that compiles and runs!!!!!

Elijah,

 

I was reviewing your reply to use BulkActivitiesService and am unable to determine what to do.  I read the doc several times and just can not figure out how to use it.  It doesn't explain what some of the parameters are or how to use them. 

 

Please tell me there is some other documentation that actually explains how the code works?  Even looking at the source that is available still does not explain how to use the API.  It shouldn't be that difficult to figure out what I am trying to do.

 

Create A List

Add contacts to that list

Create an email campaign

Send that campaign to the list of contacts

Hello,

 

The structure for bulk can definitely be confusing, so I've created a quick mockup to show how this can be done.

 

// Initialize objects and the service
BulkActivityService _activityService = _factory.createBulkActivitiesService();
AddContactsRequest contactsToAdd = new AddContactsRequest();
List<String> contactLists = new List<String>();
List<String> columns = new List<String>();
List<ContactData> importData = new List<ContactData>();

// Set up lists and columns for import
// Column names can be found at http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html
contactLists.add("LIST_ID"); // NOTE: Replace this with the IF for the list you wish to use
columns.add("EMAIL ADDRESS");
columns.add("FIRST NAME");
columns.add("LAST NAME");
contactsToAdd.setColumnNames(columns);
contactsToAdd.setLists(contactLists);

// Create the data for a single contact and add it to the import data
// NOTE: You must replace EMAIL and NAME fields with appropriate values here ContactData newContact = new ContactData(); List<String> emails = new List<String>(); emails.add("EMAIL ADDRESS"); newContact.setEmailAddresses(emails); newContact.setFirstName("FIRST NAME"); newContact.setLastName("LAST NAME"); importData.add(newContact); // Assign the import data and start the upload contactsToAdd.setImportData(importData); _activityService.addContacts(contactsToAdd);

Hopefully this is enough to get that piece in order. If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer

Hi Elijah,

 

Once again, thank you for your assistance.  This is definitely what I am looking for.  I need to ask, is it my lack of Java understanding that I could not figure this out on my own?  Since I have more to go on this project like adding campaigns and sending emails then tracking those campaigns, how would I figure out the steps to complete those tasks without your help to outline them?

 

It seems like the Javadoc is not enough ( for me at least ) to figure that out.  Is there any other doc or anyway of figuring this out on my own?

Hello,

 

Unfortunately we don't have any additional documentation on the SDK, but it might help a great deal with understanding the process for completing those actions to review our actual API documentation on the topic. For example, you can get a good idea for how our flow for creating campaigns works by reading this document: http://developer.constantcontact.com/docs/email-campaigns/email-campaign-api-index.html

 

In terms of understanding the SDK, the easiest way to find what you need is to look for a service that's related to the task you need to perform. For example, creating and updating email campaigns is done through the EmailCampaignService using the EmailCampaignRequest class as a container for the campaign itself. For scheduling you would use the EmailCampaignScheduleService which uses the EmailCampaignSchedule class.

 

In other areas of the SDK you can find this same pattern used to implement our JSON REST API, where you will have a service that wraps the interactions with the API, and each service uses classes that represent the JSON objects that are used by our API.

 

If your development environment provides an easy way to review classes in your code, that's one quick way to see what methods and properties are exposed on the various classes that are implemented. Alternatively you can easily review the classes using the GitHub respoitory browser here: https://github.com/constantcontact/java-sdk/tree/master/src/main/java/com/constantcontact/components

 

Hopefully this helps to provide some insight!

 

Sincerely,

Elijah G.
API Support Engineer

Elijah,

 

That is the doc I've been looking for.  Thank you so much.  I can't believe I didn't see that.  I was reading the source but it didn't explain what many of the parameters were for.  This doc seems to do that.

 

I'm hoping I can figure this out from here!  Thank you again for all your help!

Developer Portal

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

Visit Page