Using Campaign Monitor with Codenvy

Use Codenvy Factory to instantly start working with a sample Campaign Monitor API project:

This tutorial will explain the details of integrating the Campaign Monitor API into Codenvy. Campaign Monitor API allows the integration of your application with Campaign Monitor to be able to create mailing lists, add subscribers to your mailing lists and then send the users well designed campaign newsletters. The explanation has been done with a very basic Java project that makes use of the Campaign Monitor API to explain some basic features provided by the API.

Register With Campaign Monitor

Before proceeding to the creation of the Java project, please register at with your email id to create your account and generate the API key which will be used for the integration:


On registering, you will receive an email asking for confirming your email address and after successful confirmation, you can see your API key at the ‘Account Settings’ section:


You can get more information about the Campaign Monitor API at There are different subsections providing information about various types of functionalities offered by the API such as creating mailing lists, adding subscribers, creating campaign newsletters, sending campaigns. Each subsection will detail the request URL required to invoke the specific API method that you can use in your integration process and the list of input parameters and the response fields.
There is also a Java wrapper available for the API at which provides interface methods for all the API functionalities. Our sample Codenvy project uses the Java wrapper to explain the usage of the API.

Create a Project

Now, login to your Codenvy workspace and create a WAR project named as ‘CampaignMonitorSample’. This will have the following structure:

Create pom.xml File

To make use of the Campaign Monitor API through the Java wrapper, please update the pom.xml to include the Java wrapper ‘createsend-java’ jar into your project as Maven dependency:

      <name>Maven Repository Switchboard</name>

This will include this jar in your project as follows:

Create Java Class

Now create a Java class named that will talk to the Campaign Monitor API via the Java wrapper and invoke various functionalities of the API. The Java class authenticates the API calls with the API key, creates a client, creates a mailing list for the client and adds a subscriber to the mailing list and then creates a campaign newsletters for the mailing list and then sends the campaign. All this is done inside the method execute() in the sample source Java class.

   public void execute() throws CreateSendException {
        ApiKeyAuthenticationDetails auth = new ApiKeyAuthenticationDetails(
        Clients clientAPI = new Clients(auth);
        Client newClient = new Client();
        newClient.CompanyName = "abcpqr";
        newClient.Country = "United Kingdom";
        newClient.TimeZone = "(GMT) Coordinated Universal Time";
        newClient.ClientID = clientAPI.create(newClient);
        System.out.printf("Result of client create: %s\n", clientAPI.getClientID());
        Lists listAPI = new Lists(auth);
        Date subscribersFrom = new Date();
        List list = new List();
        list.Title = "Java API Test List";
        list.ConfirmedOptIn = false;
        list.UnsubscribeSetting = "OnlyThisList";
        listAPI.create(clientAPI.getClientID(), list);
        System.out.printf("Result of list create: %s\n", listAPI.getListID());
        System.out.printf("Result of list details: %s\n", listAPI.details());
        CustomFieldForCreate customField = new CustomFieldForCreate();
        customField.DataType = "Text";
        customField.FieldName = "Website";
        String key = listAPI.createCustomField(customField);
        Subscribers subscriberAPI = new Subscribers(auth, listAPI.getListID());
        SubscriberToAdd subscriber = new SubscriberToAdd();
        subscriber.Resubscribe = true;
        subscriber.EmailAddress = "";
        subscriber.Name = "Java Test Sub 1";
        subscriber.CustomFields = new CustomField[] {
            new CustomField()
        subscriber.CustomFields[0].Key = key;
        subscriber.CustomFields[0].Value = "";
        System.out.printf("Result of subscriber add: %s\n", subscriberAPI.add(subscriber));
        Campaigns campaignAPI = new Campaigns(auth);
        Date resultsAfter = new Date();
        CampaignForCreation newCampaign = new CampaignForCreation();
        newCampaign.FromEmail = "";
        newCampaign.FromName = "Java Wrapper";
        newCampaign.HtmlUrl = URI.create(
        newCampaign.TextUrl = URI.create(
        newCampaign.ListIDs = new String[] { listAPI.getListID() };
        newCampaign.Name = "API Testing Campaign: " + new Date();
        newCampaign.ReplyTo = "";
        newCampaign.SegmentIDs = new String[0];
        newCampaign.Subject = "Java Wrapper Test: " + new Date();

        campaignAPI.create(clientAPI.getClientID(), newCampaign);
        System.out.printf("Result of campaign create: %s\n", campaignAPI.getCampaignID());
        Date scheduledDate = new Date();
        campaignAPI.send("", scheduledDate);

        System.out.printf("Result of get campaign summary: %s\n", campaignAPI.summary());

Create index.jsp File

Your Codenvy project will have an index.jsp which will invoke the Java class -

    com.codenvy.CampaignMonitorSample campaignMonitorSample = new com.codenvy.CampaignMonitorSample();

Now you build and run your Codenvy project and the system out statements will be displayed in the browser thereby showing the successful completion of each action:


At the same time, you can check your Campaign Monitor account and you will see the mailing list and the campaign created and the details of the campaign. Also, the recipients will have received your campaign newsletter as well:



In a similar way, you can use other available API methods and integrate the Campaign Monitor API into your application to meet your application needs.