cancel
Showing results for 
Search instead for 
Did you mean: 

Java sdk missing examples and classes?

Highlighted
Occasional Participant

Java sdk missing examples and classes?

So I am new to the java api and after a lot of research I'm still confused on how to do simple things such as creating a contact and adding it to a list. Let me start with the sdk.  I added the maven dependancy suggested in the sdk readme.

<dependencies>
    <dependency>
        <groupId>com.constantcontact</groupId>
        <artifactId>java-sdk</artifactId>
        <version>5.0.3</version>
    </dependency>
</dependencies>

 

 

Once downloaded and added to the project the jar only contains the service classes and not the other object classes such as Contact, Address, and its missing all factory classes. See the image below for what the jar contains:
Capture.PNG

 

I'm not sure what I can do with only the services.  When I look at the javadoc it looks like I eventually want to a method in ContactService.java

 

 Call<Contact> createContact(@Body Contact contact, @Query("action_by") OptInSource optInSource);

 

but how can I do this without the Contact class or the OptInSource classes?

 

 

Second issue: maybe this is explained in the example files or something but they seem to be missing for the java sdk.  All the other sdks have examples included where are the java ones?

.net examples https://github.com/constantcontact/.net-sdk/tree/master/ContactExample

ruby examples https://github.com/constantcontact/ruby-sdk/tree/master/examples
php examples https://github.com/constantcontact/php-sdk/tree/master/examples

iOS examples https://github.com/constantcontact/ios-sdk/tree/master/Examples

java examples ?  don't exist

 

I found this page in the dev docs: https://developer.constantcontact.com/libraries/sample-code.html

All of the languages have links to examples, including java.  The issue is when you click on the java examples it takes you to a 404 page.
The 2 java links on the above page are:
https://github.com/constantcontact/java-sdk/tree/master/AndroidExamples/CreateAndScheduleCampaign
https://github.com/constantcontact/java-sdk/tree/master/AndroidExamples/AddOrUpdateContacts

If you could give me some guidance on how to get started.  Is the jar missing classes I need?  Are there java examples anywhere?  All I need to do with the api is to create a contact and assign it a listId, if the contact exists then I update the list.  That seems like super easy stuff, but I'm struggling to understand the jar and documentation.

8 REPLIES 8
Moderator

Re: Java sdk missing examples and classes?

Hello,

Thank you for reaching out to the API Support team here at Constant Contact.

First, I would like to mention that in looking at this for you we found that we were missing a method to get a contact by email address so as to check if they already exist or not. We have since updated the SDK so you should update to our most recent 5.0.4 version so as to take advantage of this call.

Are you downloading the java-sdk jar directly from Github or are you using a central repository to install the SDK?

If you are downloading directly from Github, you will want to also download the components jar from our releases page: https://github.com/constantcontact/java-sdk/releases -- The components package is a dependency in the lib and contains the objects you are missing.

The Java examples that were linked on our sample code page are a part of our previous Java SDK. Thank you for letting us know that these links are no longer functioning.

 

The examples in the current SDK's readme give information on how calls are created and used, and the full documentation of every call that can be made is in http://constantcontact.github.io/java-sdk

Please let me know if you have any other questions!

Sincerely,
David B.
API Support Specialist

Occasional Participant

Re: Java sdk missing examples and classes?

Thank you for the help.  I didn't manaully install the jar from github, I just added the maven dependancy and let it download itself. Is there a different dependancy to use to get the components jar or should I download and add it manually?

 

Thanks Again,

 

Tyler

Occasional Participant

Re: Java sdk missing examples and classes?

Ok I was able to get the new 5.0.4 jar and its componets installed and now I have my classes.  I'm still struggling a little to find which classes to use to actually make the call to your api. 

 

Here is the test method I created can you tell me what I am doing wrong:

 @Path("/testConstantContact")
@GET
public String testConstantContact() {
CCApi2 api = new CCApi2("your_api_key", "your_access_token");
Contact contact = new Contact();

com.constantcontact.v2.contacts.Address address = new com.constantcontact.v2.contacts.Address();
address.setLine1("123 Test Rd");
address.setLine2("");
address.setCity("Ogden");
address.setCountryCode("US");
address.setPostalCode("84404");

com.constantcontact.v2.contacts.Address[] addresses = new com.constantcontact.v2.contacts.Address[1];
addresses[0] = address;
contact.setAddresses(addresses);

ContactListMetaData md = new ContactListMetaData();
md.setId("15"));
ContactListMetaData[] contactListMetaData = new ContactListMetaData[1];
contactListMetaData[0] = md;
contact.setContactLists(contactListMetaData);

EmailAddress emailAddress = new EmailAddress();
emailAddress.setEmailAddress("tyler@fabuso.com");
EmailAddress[] emailAddresses = new EmailAddress[1];
emailAddresses[0] = emailAddress;
contact.setEmailAddresses(emailAddresses);
contact.setFirstName(mi.getFirstName());
contact.setLastName(mi.getLastName());
contact.setHomePhone(mi.getCustomerInfoId().getHomePhone());

api.getContactService().createContact(contact, OptInSource.ACTION_BY_OWNER);
}

I get the error at the end when calling: 

api.getContactService().createContact(contact, OptInSource.ACTION_BY_OWNER);

The error is: "Referenced method uses a type which is not available: retrofit2.Call<com.constantcontact.v2.Contact>".  So are there more classes I'm missing? Or is there some way to send off to the api which I didn't get correctly from the couple examples you did have of other api calls?

 

 

 

Moderator

Re: Java sdk missing examples and classes?

Glad you were able to get that installed. So I can give you the most accurate information, can you provide me with a bit more information? Regarding the annotations, what are you trying to do with it, and why are you using Retrofit annotations?

 

Also, it looks like you aren't actually executing the call. api.getContactServie().createContact().execute() or .enqueue()

 

Getting a contact or creating a contact works the same. So by taking your example and adapting it to our Synchronous method example, it could look something like this:

 

CCApi2 api = new CCApi2("your_api_key", "your_access_token");
Contact contact = new Contact();

    com.constantcontact.v2.contacts.Address address = new com.constantcontact.v2.contacts.Address(); 
    address.setLine1("123 Test Rd");
    address.setLine2("");
    address.setCity("Ogden");
    address.setCountryCode("US");
    address.setPostalCode("84404");
 
    com.constantcontact.v2.contacts.Address[] addresses = new com.constantcontact.v2.contacts.Address[1];
    addresses[0] = address;
    contact.setAddresses(addresses);
   
    ContactListMetaData md = new ContactListMetaData();
    md.setId("15"));
    ContactListMetaData[] contactListMetaData = new ContactListMetaData[1];
    contactListMetaData[0] = md;
    contact.setContactLists(contactListMetaData);

    EmailAddress emailAddress = new EmailAddress();
    emailAddress.setEmailAddress("tyler@fabuso.com");
    EmailAddress[] emailAddresses = new EmailAddress[1];
    emailAddresses[0] = emailAddress;
    contact.setEmailAddresses(emailAddresses); 
    contact.setFirstName(mi.getFirstName());
    contact.setLastName(mi.getLastName());
    contact.setHomePhone(mi.getCustomerInfoId().getHomePhone());

try {
    api.getContactService().createContact(contact, OptInSource.ACTION_BY_OWNER).execute();
} catch (IOException e) {
    // Handle exception
}
Occasional Participant

Re: Java sdk missing examples and classes?

Thank you again for the help.  So to be honest I am not quite sure what you mean by retrofit annotations, if I am using them I am not meaning to, I just used did what I thought I needed based off the examples.  The two annotations at the top of my method, the @PATH, and @GET are just there to expose an endpoint to my server I can use for testing.   Once I get the test code running I move the pieces I need out to a real implementation. 

As far as executing the command I edited it to look like this:

                try {
//line 101		String response = api.getContactService().createContact(contact, OptInSource.ACTION_BY_OWNER).execute();
		} catch (Exception e) {
			System.out.println("error creating contact");
		}


It still won't compile giving me the same error complaining about the 'createContact' call on line 101:
"Referenced method uses a type which is not available: retrofit2.Call<com.constantcontact.v2.Contact>"

Also is line 101 how I capture the response from your server?  or is there a designated object I should use to get back the response?


Thanks

 

Tyler

Moderator

Re: Java sdk missing examples and classes?

Thanks for that information. Your use of annotations makes sense. Knowing that, it shouldn't be an issue.

I see you are trying to send this to a String, and then also trying to expect a string in response. If successful, this call will return a Contact object and not a String. You can return this to the existing Contact object you created earlier, so line 101 can look like:

contact = api.getContactService().createContact(contact, OptInSource.ACTION_BY_OWNER).execute();


Having said that, if you are still trying to put this into public String testConstantContact() { } you will need to return a string somewhere, so you may consider creating a string from a piece of information from the Contact object.

Let me know if you are still having issues compiling after updating this, as this could be related.

Sincerely,
David B.
API Support Specialist

Occasional Participant

Re: Java sdk missing examples and classes?

Thank you again for the help.  After updating my code to what you said its the same thing.  Here is more information.

The entire method is here:

testCreateContact with error..PNG

 

and here is the compile script it generaetes when it fails.errorSnip.PNG

 

With the error being "cannot access call" which points back to the line that calls the "createContact" method.

 

Thanks again for all the help hopefully this helps explain my problem.

Moderator

Re: Java sdk missing examples and classes?

Sorry that you're still getting this error.

 

At this point I think it would be best to send us an email at webservices@constantcontact.com and if possible include the full stack trace from your build failure so that we can get more in depth into what could be causing this issue.

 

Sincerely,
David B.
API Support Specialist