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.

Java API when adding a campaign I'm getting errors on missing values

Highlighted
Occasional Contributor

Java API when adding a campaign I'm getting errors on missing values

It appears I am missing information from the message_footer.  I thought those values were put in from the "cutom" template? Do I just add those values myself?  Is there a way to generate a "custom" template that the api will use for those values?

 

[
RawApiRequestError [errorKey=json.type.invalid, errorMessage=#/message_footer/address_line_1: Value is of a disallowed type. Allowed types are: String.],
RawApiRequestError [errorKey=json.type.invalid, errorMessage=#/message_footer/city: Value is of a disallowed type. Allowed types are: String.],
RawApiRequestError [errorKey=json.type.invalid, errorMessage=#/message_footer/country: Value is of a disallowed type. Allowed types are: String.],

4 REPLIES 4
Highlighted
Honored Contributor

Re: Java API when adding a campaign I'm getting errors on missing values

Hello,

 

This error that you're seeing is a result of a partial message footer object being present in the API payload that does not contain the fields that were mentioned. The logic that's at work here is that the footer as a whole is optional, but if the footer is present, then these fields are required.

 

Would you be able to share a snippet of your code showing how you're creating the campaign object and then calling the service?

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: Java API when adding a campaign I'm getting errors on missing values

public static EmailCampaignResponse createEmailCampaign( Document eBlastDocument, ContactList propertyContactList )
	{
		IEmailCampaignService anEmailCampaignService = _factory.createEmailCampaignService();
		EmailCampaignRequest anEmailCampaignRequest = new EmailCampaignRequest();
		EmailCampaignResponse anEmailCampaignResponse = null;
		
		try
		{
			anEmailCampaignRequest.setEmailContent( eBlastDocument.getItemValueString("Body" ) );
			anEmailCampaignRequest.setFromEmail( Config.instance().getLmsEblastFromEmailAddress() );
			anEmailCampaignRequest.setFromName( Config.instance().getLmsEblastFromEmailName() );
			anEmailCampaignRequest.setName( propertyContactList.getName() + " - " + propertyContactList.getContactCount() );
			anEmailCampaignRequest.setReplyToEmail( Config.instance().getLmsEblastFromEmailAddress() );
			anEmailCampaignRequest.setSubject( eBlastDocument.getItemValueString( "DocTitle" ) );
			anEmailCampaignRequest.setTextContent( eBlastDocument.getItemValueString( "AnnouncementText"));
			anEmailCampaignRequest.setTemplateType( "CUSTOM" );
			
			anEmailCampaignResponse = anEmailCampaignService.addCampaign( anEmailCampaignRequest );
			System.out.println( anEmailCampaignResponse );
			
		} catch( Exception e )
		{
			e.printStackTrace();
		}
		
		return anEmailCampaignResponse;
	}
Highlighted
Honored Contributor

Re: Java API when adding a campaign I'm getting errors on missing values

Thank you for this code snippet! I was able to reproduce the problem and the issue is actually a problem with how our JSON serializer is set up. Currently it will always include the footer, even if it is null, meaning that an error will also be present unless the three fields specified in the error are set.

 

I am working on a fix for this, as well as a cleanup on some other issues that I found in the SDK and should have an update for this today or tomorrow!

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Honored Contributor

Re: Java API when adding a campaign I'm getting errors on missing values

Hello,

 

I was able to get this fixed, and also resolved a separate issue that was causing the build to fail on Java 8. The update is live at https://github.com/constantcontact/java-sdk. You'll need to download the source and build it again. Once you've done that, you'll need one additional line of code if you wish to explicitly not send a footer (thus using the pre-defined footer):

anEmailCampaignRequest.setMessageFooter(null);

Let me know if you run into any issues!

 

Sincerely,

Elijah G.
API Support Engineer
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