This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Marketing in Planyo

The first use case in the Planyo business scenario is marketing. This page describes the relevant tasks and the operations you use in the Planyo connector and the other ESB connectors. It contains the following sections:

 

Overview

The flow for marketing is illustrated in the following diagram. The ESB connectors for Constant Contact, Facebook and Gmail will be used to connect to each service. 

Retrieving vouchers

  1. Retrieve vouchers from the Planyo API using the listVouchers operation and then create a campaign using the createCampaign operation in the Constant Contact API for the above retrieved vouchers and market them by sending the campaign using the createSchedule operation. 
  2. Using the sendMessage operation, to send voucher details to Planyo users as e-mail notifications via Mandrill. 

Planyo operations
Constant Contact operations
Mandrill operations

Note

Time zone of Constant Contact should always be 'London, United Kingdom' in order to get the exact same scheduled time of the Constant Contact mail campaign.

    • E-mail campaign will be created and scheduled only if Constant Contact API token has been provided
    • E-mail notification will be sent to Planyo users only if the Mandrill API key has been provided

Prerequisites

Should consist of a contact list with a single(at least) contact in Constant Contact. Make sure to verify e-mail addresses of contacts which belongs to that created contact list in Constant Contact. To verify e-mail addresses navigate to My Account -> My Settings -> Verify Address in the Constant Contact account.

Observations

Created e-mail campaigns will not be sent at scheduled time in the Constant Contact trial account and campaigns may delay to deliver.


Samples
Sample Template for creating a campaign in Constant Contact and sending the campaign to the contact list
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<!-- This template is responsible to create a campaign in ConstantContact and send the campaign to contact list. Independently this will send voucher details to existing users in Planyo as an email notification via the Mandrill API -->
<template xmlns="http://ws.apache.org/ns/synapse" name="planyo-sendCampaignAndNotify">
   <!-- Constant Contact parameters -->
   <parameter name="constantContact.apiUrl" description="The constantContact API URL." />
   <parameter name="constantContact.apiToken" description="Encrypted alphanumeric string to authenticate the Constant Contact credentials." />
   <parameter name="constantContact.apiKey" description="The constantContact API Key." />
   <parameter name="constantContact.fromEmail" description="The name of the campaign." />
   <parameter name="constantContact.sendToContactList" description="The contactList id to send the campaign." />
   <parameter name="constantContact.replyToEmail" description="The email address to send replies." />
   <parameter name="constantContact.fromName" description="The campaign sender's name." />
   <parameter name="constantContact.templateBody" description="Part of the email content of the campaign." />
   <parameter name="constantContact.sheduledDate" description="The sheduled date to send the campaign." />
   <parameter name="constantContact.campaignName" description="Unique name to create a campaign." />
   <!-- Mandrill Parameters -->
   <parameter name="mandrill.apiUrl" description="Base endpoint URL of Mandrill API." />
   <parameter name="mandrill.apiKey" description="API Key to access data of Mandrill account." />
   <parameter name="mandrill.to" description="An array of recipient information." />
   <sequence>
      <property name="constantContact.apiUrl" expression="$func:constantContact.apiUrl" />
      <property name="constantContact.apiToken" expression="$func:constantContact.apiToken" />
      <property name="constantContact.apiKey" expression="$func:constantContact.apiKey" />
      <property name="constantContact.fromEmail" expression="$func:constantContact.fromEmail" />
      <property name="constantContact.sendToContactList" expression="$func:constantContact.sendToContactList" />
      <property name="constantContact.replyToEmail" expression="$func:constantContact.replyToEmail" />
      <property name="constantContact.fromName" expression="$func:constantContact.fromName" />
      <property name="constantContact.templateBody" expression="$func:constantContact.templateBody" />
      <property name="constantContact.sheduledDate" expression="$func:constantContact.sheduledDate" />
      <property name="constantContact.campaignName" expression="$func:constantContact.campaignName" />
      <property name="mandrill.apiUrl" expression="$func:mandrill.apiUrl" />
      <property name="mandrill.apiKey" expression="$func:mandrill.apiKey" />
      <property name="mandrill.to" expression="$func:mandrill.to" />
      <property name="constantContact.subject" value="Exciting Planyo Vouchers" />
      <property name="constantContact.textContent" value="This email is not supported HTML preview." />
      <!-- BEGIN: Process creation of campaign only if the access token is given -->
      <filter source="boolean(get-property('constantContact.apiToken'))" regex="true">
         <then>
            <constantcontact.init>
               <apiUrl>{$ctx:constantContact.apiUrl}</apiUrl>
               <apiToken>{$ctx:constantContact.apiToken}</apiToken>
               <apiKey>{$ctx:constantContact.apiKey}</apiKey>
            </constantcontact.init>
            <constantcontact.createCampaign>
               <subject>{$ctx:constantContact.subject}</subject>
               <emailContentFormat>HTML</emailContentFormat>
               <emailContent>{$ctx:constantContact.templateBody}</emailContent>
               <name>{$ctx:constantContact.campaignName}</name>
               <fromEmail>{$ctx:constantContact.fromEmail}</fromEmail>
               <greetingString>Welcome</greetingString>
               <replyToEmail>{$ctx:constantContact.replyToEmail}</replyToEmail>
               <sentToContactLists>{$ctx:constantContact.sendToContactList}</sentToContactLists>
               <fromName>{$ctx:constantContact.fromName}</fromName>
               <textContent>{$ctx:constantContact.textContent}</textContent>
            </constantcontact.createCampaign>
            <property name="uri.var.campaignId" expression="json-eval($.id)" />
            <!-- If campaign creation failed construct error message, if success gives successful message -->
            <filter xpath="get-property('uri.var.campaignId') = 'null'">
               <then>
                  <property name="campaignId" value="{}" />
                  <property name="status" value="Error" />
                  <property name="message" expression="json-eval($.)" />
               </then>
               <else>
                  <property name="campaignId" expression="fn:concat('{campaignId:',get-property('uri.var.campaignId'),'}')" />
                  <property name="status" value="Success" />
                  <property name="message" value="Constant Contact email campaign has been successfully created" />
               </else>
            </filter>
            <!-- Calling the response handler template to give custom error message when campaign creation successful -->
            <call-template target="responseHandlerTemplate">
               <with-param name="id" value="{$ctx:campaignId}" />
               <with-param name="activity" value="constantcontact_createCampaign" />
               <with-param name="status" value="{$ctx:status}" />
               <with-param name="message" value="{$ctx:message}" />
            </call-template>
            <!-- BEGIN: Shedule the campaign, only if campaign is created -->
            <filter xpath="get-property('uri.var.campaignId') != 'null'">
               <then>
                  <constantcontact.init>
                     <apiToken>{$ctx:constantContact.apiToken}</apiToken>
                     <apiUrl>{$ctx:constantContact.apiUrl}</apiUrl>
                     <apiKey>{$ctx:constantContact.apiKey}</apiKey>
                  </constantcontact.init>
                  <constantcontact.createSchedule>
                     <campaignId>{$ctx:uri.var.campaignId}</campaignId>
                     <scheduledDate>{$ctx:constantContact.sheduledDate}</scheduledDate>
                  </constantcontact.createSchedule>
                  <property name="uri.var.campaignSendId" expression="json-eval($.id)" />
                  <!-- If created campaign is schedule to be sent gives successful message, otherwise gives error message -->
                  <filter xpath="get-property('uri.var.campaignSendId') = 'null'">
                     <then>
                        <property name="campaignSendId" value="{}" />
                        <property name="status" value="Error" />
                        <property name="message" expression="json-eval($.)" />
                     </then>
                     <else>
                        <property name="campaignSendId" expression="fn:concat('{campaignSendId:',get-property('uri.var.campaignSendId'),'}')" />
                        <property name="status" value="Success" />
                        <property name="message"
                           expression="fn:concat('Campaign has been sheduled for - [',get-property('constantContact.sheduledDate'),']')" />
                     </else>
                  </filter>
                  <!-- Calling the response handler template to give custom error message when campaign scheduling is successful -->
                  <call-template target="responseHandlerTemplate">
                     <with-param name="id" value="{$ctx:campaignSendId}" />
                     <with-param name="activity" value="constantcontact_sheduledCampaign" />
                     <with-param name="status" value="{$ctx:status}" />
                     <with-param name="message" value="{$ctx:message}" />
                  </call-template>
               </then>
            </filter> <!-- END: Shedule the campaign -->
         </then>
      </filter> <!-- END: Process creation of campaign if access token provided -->
      <!-- BEGIN: Process send email notification if api key of Mandrill is given otherwise give error message -->
      <filter source="boolean(get-property('mandrill.apiKey'))" regex="true">
         <then>
            <!-- BEGIN: If user not provided from email set status as Error -->
            <filter source="boolean(get-property('constantContact.fromEmail'))" regex="false">
               <then>
                  <property name="status" value="Error" />
               </then>
            </filter> <!-- END: If user not provided from email -->
            <mandrill.init>
               <apiUrl>{$ctx:mandrill.apiUrl}</apiUrl>
               <apiKey>{$ctx:mandrill.apiKey}</apiKey>
               <format>json</format>
            </mandrill.init>
            <mandrill.sendMessage>
               <html>{$ctx:constantContact.templateBody}</html>
               <subject>{$ctx:constantContact.subject}</subject>
               <fromEmail>{$ctx:constantContact.fromEmail}</fromEmail>
               <fromName>{$ctx:constantContact.fromName}</fromName>
               <important>false</important>
               <autoHtml>true</autoHtml>
               <to>{$ctx:mandrill.to}</to>
            </mandrill.sendMessage>
            <property name="mandrillSendMessageStatusCode" expression="$axis2:HTTP_SC" />
            <!-- BEGIN: If mandrill sendMessage successful give success response else gives error message -->
            <filter xpath="get-property('mandrillSendMessageStatusCode') != 200">
               <then>
                  <property name="status" value="Error" />
                  <property name="message" expression="json-eval($.)" />
               </then>
               <else>
                  <property name="sentEmails" expression="json-eval($.)" />
                  <!-- Script mediator to iterate each and every sent email response by checking sent status of emails to construct successful message or error message -->
                  <script language="js">
                     <![CDATA[
                        
                        var sentEmails = eval("(" + mc.getProperty('sentEmails') + ")");
                        var sentEmailCount = 0;
                        for(var index in sentEmails){
                           var status = sentEmails[index].status;
                           if(status == 'sent' || status == 'queued'){
                              sentEmailCount += 1;
                           }
                        }
                        if(sentEmailCount > 0){
                           mc.setProperty('isSentEmailAvailable', 'true');
                        } else {
                           mc.setProperty('isSentEmailAvailable', 'false');
                        }
                        
                     ]]>
                  </script>
                  <!-- BEGIN: If at least one sent email message available construct success message else construct error message -->
                  <filter xpath="get-property('isSentEmailAvailable') = 'true'">
                     <then>
                        <property name="status" value="Success" />
                        <property name="message" expression="json-eval($.)" />
                     </then>
                     <else>
                        <property name="status" value="Error" />
                        <property name="message" expression="json-eval($.)" />
                     </else> 
                  </filter> <!-- END: If at least one sent email message -->
               </else>
            </filter> <!-- If mandrill sendMessage successful -->
         </then>
      </filter> <!-- END: Process of send email notification -->
   </sequence>
</template>
 
Sample Proxy for retrieving vouchers from Planyo, then creating an e-mail campaign in Constant Contact for the retrieved vouchers and marketing them by sending the e-mail campaign
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="planyo_retrieveVouchersAndMarketing" transports="https http" startOnLoad="true" trace="disable">
   <target>
      <inSequence>
         <!-- Planyo Properties -->
         <property name="planyo.apiUrl" value="http://api.planyo.com" />
         <property name="planyo.apiKey" expression="json-eval($.planyoApiKey)" />
         <property name="planyo.version" value="1" />
         <property name="planyo.language" value="EN" />
         <property name="planyo.rentalStartTime" expression="json-eval($.planyoRentalStartTime)" />
         <property name="planyo.rentalEndTime" expression="json-eval($.planyoRentalEndTime)" />
         <!-- ConstantContact Properties -->
         <property name="constantContact.apiUrl" value="https://api.constantcontact.com" />
         <property name="constantContact.apiToken" expression="json-eval($.constantContactApiToken)" />
         <property name="constantContact.apiKey" expression="json-eval($.constantContactApiKey)" />
         <property name="constantContact.fromEmail" expression="json-eval($.fromEmail)" />
         <property name="constantContact.sendToContactList" expression="json-eval($.constantContactSentToContactLists)" />
         <property name="constantContact.replyToEmail" expression="json-eval($.constantContactReplyToEmail)" />
         <property name="constantContact.fromName" expression="json-eval($.fromName)" />
         <property name="constantContact.campaignName" expression="json-eval($.constantContactCampaignName)" />
         <!-- Mandrill Properties -->
         <property name="mandrill.apiUrl" value="https://mandrillapp.com" />
         <property name="mandrill.apiKey" expression="json-eval($.mandrillApiKey)" />
         <property name="mandrill.to" value="" scope="operation" />
         <property name="userIndex" expression="0" scope="operation" />
         <!-- All vouchers details retreive that user required by calling listVouchers method in planyo connector -->
         <planyo.init>
            <apiUrl>{$ctx:planyo.apiUrl}</apiUrl>
            <apiKey>{$ctx:planyo.apiKey}</apiKey>
            <version>{$ctx:planyo.version}</version>
            <language>{$ctx:planyo.language}</language>
         </planyo.init>
         <planyo.listVouchers>
            <rentalStartTime>{$ctx:planyo.rentalStartTime}</rentalStartTime>
            <rentalEndTime>{$ctx:planyo.rentalEndTime}</rentalEndTime>
            <resourceId>{$ctx:resourceId}</resourceId>
            <siteId>{$ctx:siteId}</siteId>
            <voucherCodePrefix>{$ctx:voucherCodePrefix}</voucherCodePrefix>
            <isCheckReservationTime>{$ctx:isCheckReservationTime}</isCheckReservationTime>
         </planyo.listVouchers>
         <property name="responseCode" expression="json-eval($.response_code)" />
         <!-- BEGIN: If planyo vouchers successfully retrieved -->
         <filter xpath="get-property('responseCode') != 0">
            <then>
               <property name="id" value="{}" />
               <property name="message" expression="json-eval($.)" />
               <!-- Response generator if vouchers not successfully retrieved -->
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="planyo_retrieveVouchers" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="Error" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
            <else>
               <property name="results" expression="json-eval($.)" />
               <!-- Script mediator to construct the email campaign body using retreived voucher details -->
               <script language="js">
                  <![CDATA[
                     
                     var voucherResults = eval("(" + mc.getProperty('results') + ")");
                     var templateBody = "<html><head><style>table, th, td {border: 1px solid black;border-collapse: collapse;}th, td {padding: 5px;text-align: left;}</style></head><body><h4>Dear user,</h4><p>Planyo has introduced exciting vouchers. Please find more details as follows.</p>";
                     var voucherCount = 0;
                     
                     //Construct email campaign template body with the voucher details
                     for (var key in voucherResults.data.results) {
                          templateBody += "<table style='width:100%'><tr><th colspan='2'>Voucher Code: " + voucherResults.data.results[key].code + "</th></tr>";
                          templateBody += "<tr><td>Available Quantity</td><td>" + (voucherResults.data.results[key].quantity - voucherResults.data.results[key].quantity_used) + "</td></tr>";
                          templateBody += "<tr><td>Discount</td><td>" + voucherResults.data.results[key].discount_value + "</td></tr>";
                          templateBody += "<tr><td>Rental Period</td><td>" + voucherResults.data.results[key].rental_start_date + " to " + voucherResults.data.results[key].rental_end_date + "</td></tr>";
                          templateBody += "<tr><td>Reservation Period</td><td>" + voucherResults.data.results[key].reservation_start_date + " to " + voucherResults.data.results[key].reservation_end_date + "</td></tr></table><br/>";
                          voucherCount += 1;
                     }
                     templateBody += "<a href='https://www.planyo.com/vouchers.php'>For more details please click here</a><p>Best Regards,</p><p>" + mc.getProperty('constantContact.fromName') + "</p></body></html>";
                     
                     mc.setProperty("voucherCount", voucherCount);
                     mc.setProperty("constantContact.templateBody", templateBody);
                     
                  ]]>
               </script>
               <!-- Process campaign creation only if the voucher details are available -->
               <filter xpath="get-property('voucherCount') = 0">
                  <then>
                     <property name="id" value="{}" />
                     <!-- Response generator if no voucher details retreived -->
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="planyo_retrieveVouchers" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="Error" />
                        <with-param name="message" value="Voucher list is empty - No vouchers to be processed" />
                     </call-template>
                     <loopback />
                  </then>
                  <else>
                     <!-- Script mediator to construct future time to be schedule the campaign to be send its contact list -->
                     <script language="js">
                        <![CDATA[
                              var systemDate = new Date();
                              var minutes = systemDate.getMinutes();
                              var hours = systemDate.getHours();
                              var currentDate = "" + systemDate.getDate();
                              
                              var sheduledMins = minutes + 5;
                              if(sheduledMins < 10) {
                                 sheduledMins = "0" + sheduledMins;
                              }
                                                      
                              if(currentDate.length == 1) {
                                 currentDate = "0" + currentDate;
                              }
                              var dateString = systemDate.getFullYear() + "-" + Number(systemDate.getMonth() + 1) + "-" + currentDate;
                              
                              var sheduledDate = dateString + "T" + hours + ":" + sheduledMins + ":00.000Z";
                              
                              mc.setProperty("constantContact.sheduledDate", sheduledDate);
                        ]]>
                     </script>
                     <!-- BEGIN: Process creation and send of campaign only if the access token is given otherwise give error message -->
                     <filter source="(boolean(get-property('constantContact.apiToken')) and boolean(get-property('constantContact.apiKey')))" regex="false">
                        <then>
                           <property name="id" value="{}" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="constantcontact_createAndSendCampaign" />
                              <with-param name="id" value="{$ctx:id}" />
                              <with-param name="status" value="Skipped" />
                              <with-param name="message" value="Please provide the constant contact API Token and API Key" />
                           </call-template>
                        </then>
                        <else>
                           <!-- Calling planyo-sendCampaignAndNotify template to create and send campaign in constant contact -->
                           <call-template target="planyo-sendCampaignAndNotify">
                              <!-- Parameter values will be passed on to a sequence template -->
                              (
                              <with-param name="constantContact.apiUrl" value="{$ctx:constantContact.apiUrl}" />
                              |
                              <with-param name="constantContact.apiToken" value="{$ctx:constantContact.apiToken}" />
                              |
                              <with-param name="constantContact.apiKey" value="{$ctx:constantContact.apiKey}" />
                              |
                              <with-param name="constantContact.fromEmail" value="{$ctx:constantContact.fromEmail}" />
                              |
                              <with-param name="constantContact.sendToContactList" value="{$ctx:constantContact.sendToContactList}" />
                              |
                              <with-param name="constantContact.replyToEmail" value="{$ctx:constantContact.replyToEmail}" />
                              |
                              <with-param name="constantContact.fromName" value="{$ctx:constantContact.fromName}" />
                              |
                              <with-param name="constantContact.templateBody" value="{$ctx:constantContact.templateBody}" />
                              |
                              <with-param name="constantContact.sheduledDate" value="{$ctx:constantContact.sheduledDate}" />
                              |
                              <with-param name="constantContact.campaignName" value="{$ctx:constantContact.campaignName}" />
                              |
                              ) *
                           </call-template>
                        </else>
                     </filter> <!-- END: Process creation and send of campaign only if the access token is given -->
                     <!-- BEGIN: Process send email notification for Planyo users if api key of Mandrill is given otherwise give skipped message -->
                     <filter source="boolean(get-property('mandrill.apiKey'))" regex="false">
                        <then>
                           <property name="id" value="{}" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="mandrill_sendMessage" />
                              <with-param name="id" value="{$ctx:id}" />
                              <with-param name="status" value="Skipped" />
                              <with-param name="message" value="Please provide the mandrill API Key" />
                           </call-template>
                           <loopback />
                        </then>
                        <else>
                           <!-- Retrieve existing list of users from the Planyo by calling listUsers method -->
                           <planyo.init>
                              <apiUrl>{$ctx:planyo.apiUrl}</apiUrl>
                              <apiKey>{$ctx:planyo.apiKey}</apiKey>
                              <version>{$ctx:planyo.version}</version>
                              <language>{$ctx:planyo.language}</language>
                           </planyo.init>
                           <planyo.listUsers>
                              <page>0</page>
                              <pageSize>1000</pageSize>
                              <siteId>{$ctx:siteId}</siteId>
                              <detailLevel>{$ctx:detailLevel}</detailLevel>
                              <userFilterName>{$ctx:userFilterName}</userFilterName>
                              <userFilterValue>{$ctx:userFilterValue}</userFilterValue>
                              <userFilterValueInc>{$ctx:userFilterValueInc}</userFilterValueInc>
                              <firstName>{$ctx:firstName}</firstName>
                              <lastName>{$ctx:lastName}</lastName>
                              <email>{$ctx:email}</email>
                              <country>{$ctx:country}</country>
                              <address>{$ctx:address}</address>
                              <city>{$ctx:city}</city>
                              <zip>{$ctx:zip}</zip>
                              <phoneNumber>{$ctx:phoneNumber}</phoneNumber>
                              <phoneCountryCode>{$ctx:phoneCountryCode}</phoneCountryCode>
                              <mobileNumber>{$ctx:mobileNumber}</mobileNumber>
                              <mobileCountryCode>{$ctx:mobileCountryCode}</mobileCountryCode>
                              <isListUnconfirmed>true</isListUnconfirmed>
                           </planyo.listUsers>
                           <property name="userCount" expression="count(//users)" scope="operation" />
                           <!-- BEGIN: Loops through users and get each user's email to send notification email using Mandrill -->
                           <iterate continueParent="false" id="userIterator" preservePayload="true" expression="//users" sequential="true">
                              <target>
                                 <sequence>
                                    <!-- Retrieve each user information to send emails -->
                                    <property name="planyo.email" expression="//users/email/text()" />
                                    <property name="planyo.firstName" expression="//users/first_name/text()" />
                                    <!-- Construct Mandrill recipient information as comma seperated JSON Objects -->
                                    <property name="mandrill.to" expression="fn:concat(get-property('operation','mandrill.to'),'{ &quot;email&quot;: &quot;',get-property('planyo.email'),'&quot;, &quot;name&quot;: &quot;',get-property('planyo.firstName'),'&quot;, &quot;type&quot;: &quot;bcc&quot; },')" scope="operation"/>
                                    <property name="userIndex" expression="get-property('operation','userIndex') + 1" scope="operation" />
                                    <!-- BEGIN: Resriction filter to complete the iteration of user details -->
                                    <filter xpath="get-property('operation','userIndex') = get-property('operation', 'userCount')">
                                       <then>
                                          <!-- Construct Mandrill array of recipient information by removing last comma -->
                                          <property name="mandrill.to" expression="fn:concat('[',fn:substring(get-property('operation','mandrill.to'),1,fn:string-length(get-property('operation','mandrill.to'))-1),']')" />
                                          <property name="constantContact.apiToken" value="" />
                                          <!-- Calling planyo-sendCampaignAndNotify template to send voucher details to existing users in Planyo as an email notification via the Mandrill -->
                                          <call-template target="planyo-sendCampaignAndNotify">
                                             <!-- Parameter values will be passed on to a sequence template -->
                                             (
                                             <with-param name="mandrill.apiUrl" value="{$ctx:mandrill.apiUrl}" />
                                             |
                                             <with-param name="mandrill.apiKey" value="{$ctx:mandrill.apiKey}" />
                                             |
                                             <with-param name="mandrill.to" value="{$ctx:mandrill.to}" />
                                             |
                                             ) *
                                          </call-template>
                                          <property name="id" value="{}" />
                                          <!-- Call the responseHandler template -->
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="mandrill_sendMessage" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                          <loopback />
                                       </then>
                                    </filter> <!-- END: Restriction filter -->
                                 </sequence>
                              </target>
                           </iterate> <!-- END: Looping of users -->
                        </else>
                     </filter> <!-- END: Process send email notification for Planyo users -->
                  </else>
               </filter> <!-- END: Campaign creation process -->
            </else>
         </filter> <!-- END: If planyo vouchers successfully retrieved -->
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>
               {
                  "Response":{
                     "process":"planyo_retrieveVouchersAndMarketing",
                     "activityResponse":[$1]
                  }
               }
            </format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
   <description />
</proxy>
Sample Request for retrieving vouchers from Planyo, then creating an e-mail campaign in Constant Contact for the retrieved vouchers and marketing them by sending the e-mail campaign
{
	"planyoApiKey":"d3314e7094e0ad10714156181eff0cf4",
	"constantContactApiToken":"8c805eab-8970-47ce-b4d3-e72474be6d78",
	"constantContactApiKey":"vznzz39dtdgqfcu2d6c6njx7",
	"constantContactCampaignName":"Planyo Voucher Campaign20",
	"fromEmail":"wso2connector.abdera@gmail.com",
	"constantContactSentToContactLists":[
					{
						"id": "1874889088"
					},
					{
						"id": "2047829242"
					}
				],
	"constantContactReplyToEmail":"wso2connector.abdera@gmail.com",
	"fromName":"Planyo Team",
	"mandrillApiKey":"YkT77awdFCTbvCuwhJo4jw"
}

Mandatory and Optional Parameters

Mandatory parameters : planyoApiKey, constantContactCampaignName, fromEmail, constantContactSentToContactLists, constantContactReplyToEmail, fromName,constantContactApiToken, constantContactApiKey

Optional parameters : planyoRentalStartTime, planyoRentalEndTime, mandrillApiKey

Note

 The following are the parameter descriptions:

  • planyoApiKey: The API key of the Planyo account
  • constantContactApiToken: The API Token of the Constant Contact account
  • constantContactApiKey: The API Key of the Constant Contact account
  • constantContactCampaignName: Unique name of the e-mail campaign
  • fromEmail: The Constant Contact campaign sender's e-mail address
  • constantContactSentToContactLists: An array of containing contact list ID objects to which the campaigns should be sent
  • constantContactReplyToEmail: The e-mail address to which the subscribers can reply for the Constant Contact e-mail campaign
  • fromName: Name of the sender of the Constant Contact e-mail campaign
  • mandrillApiKey: The API key of the Mandrill account
  • planyoRentalStartTime: Planyo vouchers will return the rental to start on a specified date. Date format should be 'YYYY-MM-DD' 
  • planyoRentalEndTime: Planyo vouchers will return the rental to end on a specified date. Date format should be 'YYYY-MM-DD'

Updating contact lists

  1. Retrieve the campaign clickers from the Constant Contact API using the listCampaignClicks operation.

  2. Update an existing contact list within the Constant Contact API itself using the updateContact operation. Creating a contact list is an offline process. 
  3. Retrieve an existing list of users using the getContactById operation.
Constant Contact operations

Prerequisites

Should consist of an empty contact list in Constant Contact.

Samples 
Sample Proxy for retrieving a list of contacts from Constant Contact who have clicked on a link in the sent email campaign, and updating a contact list in Constant Contact
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="planyo_retrieveClickersAndCreateContactList" transports="https http"
   startOnLoad="true" trace="disable">
   <description />
   <target>
      <inSequence>
         <!-- ConstantContact Properties -->
         <property name="constantContact.apiUrl" value="https://api.constantcontact.com" />
         <property name="constantContact.apiToken" expression="json-eval($.constantContactApiToken)" />
         <property name="constantContact.apiKey" expression="json-eval($.constantContactApiKey)" />
         <property name="constantContact.campaignId" expression="json-eval($.constantContactCampaignId)" />
         <property name="constantContact.contactListId" expression="json-eval($.constantContactContactListId)" />
         <!-- Call constantcontact connector listCampaignClicks method to retrieve details of clickers -->
         <constantcontact.init>
            <apiUrl>{$ctx:constantContact.apiUrl}</apiUrl>
            <apiToken>{$ctx:constantContact.apiToken}</apiToken>
            <apiKey>{$ctx:constantContact.apiKey}</apiKey>
         </constantcontact.init>
         <constantcontact.listCampaignClicks>
            <campaignId>{$ctx:constantContact.campaignId}</campaignId>
         </constantcontact.listCampaignClicks>
         <!-- Remove Constant Contact response header information -->
         <header name="Content-Encoding" action="remove" scope="transport" />
         <!-- BEGIN: Process only if clickers list is retrieved successfully -->
         <filter source="$axis2:HTTP_SC" regex="200">
            <then>
               <property name="clickersCount" expression="count(//jsonObject/results)" scope="operation" />
               <property name="clickerIndex" expression="0" scope="operation" />
               <property name="contactIds" value="" scope="operation" />
               <!-- BEGIN: Process only if clickers count is not zero -->
               <filter xpath="get-property('operation', 'clickersCount') != 0">
                  <then>
                     <!-- BEGIN: If user not provide contact list ID gives error message other wise proceed the contact update process to list -->
                     <filter source="boolean(get-property('constantContact.contactListId'))" regex="false">
                        <then>
                           <property name="id" value="{}" />
                           <!-- Response generator if no campaign clickers are available in provided campaign -->
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="constantcontact_addClickersToContactList" />
                              <with-param name="id" value="{$ctx:id}" />
                              <with-param name="status" value="Error" />
                              <with-param name="message" value="The contact list does not exist. Please provide contact list id." />
                           </call-template>
                           <loopback />
                        </then>
                        <else>
                           <!-- BEGIN: For each clicker -->
                           <iterate continueParent="false" id="clickerIterator" preservePayload="true" expression="//jsonObject/results"
                              sequential="true">
                              <target>
                                 <sequence>
                                    <!-- Script mediator to sleep 1000 miliseconds to avoid Constant Contact API limitation 4 calls/sec on updating contacts -->
                                    <script language="js">
                                       <![CDATA[
                                          java.lang.Thread.sleep(1000);
                                          
                                       ]]>
                                    </script> 
                                    
                                    <property name="constantContact.contactID" expression="//results/contact_id/text()" />
                                    <!-- Call constantcontact connector getContactById method to retrieve details of the contact -->
                                    <constantcontact.init>
                                       <apiUrl>{$ctx:constantContact.apiUrl}</apiUrl>
                                       <apiToken>{$ctx:constantContact.apiToken}</apiToken>
                                       <apiKey>{$ctx:constantContact.apiKey}</apiKey>
                                    </constantcontact.init>
                                    <constantcontact.getContactById>
                                       <contactId>{$ctx:constantContact.contactID}</contactId>
                                    </constantcontact.getContactById>
                                    <!-- Remove Constant Contact response header information -->
                                    <header name="Content-Encoding" action="remove" scope="transport" />
                                    <property name="addressCount" expression="count(//jsonObject/addresses)" />
                                    <property name="constantContact.id" expression="json-eval($.id)" />
                                    <property name="constantContact.exsistingList" expression="json-eval($.lists)" />
                                    <property name="constantContact.email" expression="json-eval($.email_addresses[0].email_address)" />
                                    <property name="constantContact.firstName" expression="json-eval($.first_name)" />
                                    <property name="constantContact.middleName" expression="json-eval($.middle_name)" />
                                    <property name="constantContact.lastName" expression="json-eval($.last_name)" />
                                    <property name="constantContact.fax" expression="json-eval($.fax)" />
                                    <property name="constantContact.cellPhone" expression="json-eval($.cell_phone)" />
                                    <property name="constantContact.companyName" expression="json-eval($.company_name)" />
                                    <property name="constantContact.jobtitle" expression="json-eval($.job_title)" />
                                    <property name="constantContact.prefixName" expression="json-eval($.prefix_name)" />
                                    <property name="constantContact.homePhone" expression="json-eval($.home_phone)" />
                                    <property name="constantContact.workPhone" expression="json-eval($.work_phone)" />
                                    <property name="constantContact.customFields" expression="json-eval($.custom_fields)" />
                                    <property name="constantContact.addLine1" expression="json-eval($.addresses[0].line1)" />
                                    <property name="constantContact.addLine2" expression="json-eval($.addresses[0].line2)" />
                                    <property name="constantContact.addCity" expression="json-eval($.addresses[0].city)" />
                                    <property name="constantContact.addCountryCode" expression="json-eval($.addresses[0].country_code)" />
                                    <property name="constantContact.addType" expression="json-eval($.addresses[0].address_type)" />
                                    <property name="constantContact.actionBy" expression="json-eval($.email_addresses[0].opt_in_source)" />
                                    <!-- Process only if the contact has an address -->
                                    <filter xpath="get-property('addressCount') != 0">
                                       <then>
                                          <payloadFactory media-type="json">
                                             <format>
                                                {
                                                   "emailAddresses":[{
                                                      "email_address": "$1"
                                                   }],
                                                   "addresses":[{
                                                      "address_type": "$2",
                                                      "line1": "$3",
                                                      "line2": "$4",
                                                      "city": "$5",
                                                      "country_code": "$6"
                                                   }],
                                                   "list":{
                                                      "id":"$7"
                                                   }
                                                }
                                             </format>
                                             <args>
                                                <arg expression="get-property('constantContact.email')" />
                                                <arg expression="get-property('constantContact.addType')" />
                                                <arg expression="get-property('constantContact.addLine1')" />
                                                <arg expression="get-property('constantContact.addLine2')" />
                                                <arg expression="get-property('constantContact.addCity')" />
                                                <arg expression="get-property('constantContact.addCountryCode')" />
                                                <arg expression="get-property('constantContact.contactListId')" />
                                             </args>
                                          </payloadFactory>
                                          <property name="constantContact.addresses" expression="json-eval($.addresses)" />
                                          <property name="constantContact.email" expression="json-eval($.emailAddresses)" />
                                          <property name="constantContact.newList" expression="json-eval($.list)" />
                                          <property name="constantContact.newList" expression="fn:concat(fn:substring(get-property('constantContact.exsistingList'), 0, fn:string-length(get-property('constantContact.exsistingList'))), ',', get-property('constantContact.newList'), ']')" />
                                       </then>
                                       <else>
                                          <payloadFactory media-type="json">
                                             <format>
                                                {
                                                   "emailAddresses":[{
                                                      "email_address": "$1"
                                                   }],
                                                   "list":{
                                                      "id": "$2"
                                                   }
                                                }
                                             </format>
                                             <args>
                                                <arg expression="get-property('constantContact.email')" />
                                                <arg expression="get-property('constantContact.contactListId')" />
                                             </args>
                                          </payloadFactory>
                                          <property name="constantContact.email" expression="json-eval($.emailAddresses)" />
                                          <property name="constantContact.newList" expression="json-eval($.list)" />
                                          <property name="constantContact.newList" expression="fn:concat(fn:substring(get-property('constantContact.exsistingList'), 0, fn:string-length(get-property('constantContact.exsistingList'))), ',', get-property('constantContact.newList'), ']')" />
                                          <property name="constantContact.addresses" expression="json-eval($.addresses)" />
                                       </else>
                                    </filter>
                                    <!-- Call constantcontact connector updateContact method to add the contact to clickers contact list -->
                                    <constantcontact.init>
                                       <apiUrl>{$ctx:constantContact.apiUrl}</apiUrl>
                                       <apiToken>{$ctx:constantContact.apiToken}</apiToken>
                                       <apiKey>{$ctx:constantContact.apiKey}</apiKey>
                                    </constantcontact.init>
                                    <constantcontact.updateContact>
                                       <middleName>{$ctx:constantContact.middleName}</middleName>
                                       <lastName>{$ctx:constantContact.lastName}</lastName>
                                       <fax>{$ctx:constantContact.fax}</fax>
                                       <customFields>{$ctx:constantContact.customFields}</customFields>
                                       <cellPhone>{$ctx:constantContact.cellPhone}</cellPhone>
                                       <actionBy>{$ctx:constantContact.actionBy}</actionBy>
                                       <companyName>{$ctx:constantContact.companyName}</companyName>
                                       <homePhone>{$ctx:constantContact.homePhone}</homePhone>
                                       <prefixName>{$ctx:constantContact.prefixName}</prefixName>
                                       <contactId>{$ctx:constantContact.contactId}</contactId>
                                       <workPhone>{$ctx:constantContact.workPhone}</workPhone>
                                       <addresses>{$ctx:constantContact.addresses}</addresses>
                                       <firstName>{$ctx:constantContact.firstName}</firstName>
                                       <lists>{$ctx:constantContact.newList}</lists>
                                       <jobTitle>{$ctx:constantContact.jobTitle}</jobTitle>
                                       <emailAddresses>{$ctx:constantContact.email}</emailAddresses>
                                    </constantcontact.updateContact>
                                    <filter source="$axis2:HTTP_SC" regex="200">
                                       <then>
                                          <property name="contactIds" expression="fn:concat(get-property('operation', 'contactIds'), get-property('constantContact.contactID'), ',')" scope="operation"/>
                                          <property name="status" value="Success" />
                                          <property name="message" value="Clicker(s) successfully added to the contact list" />
                                       </then>
                                       <else>
                                          <property name="contactIds" value="" scope="operation" />
                                          <property name="status" value="Error" />
                                          <property name="message" expression="json-eval($)" />
                                       </else>
                                    </filter>
                                    <property name="clickerIndex" expression="get-property('operation','clickerIndex') + 1" scope="operation" />
                                    <!-- BEGIN: To avoid execute until final clicker to reach -->
                                    <filter xpath="get-property('operation','clickerIndex') = get-property('operation', 'clickersCount')">
                                       <then>
                                          <!-- BEGIN: Check whether contact update is not failed due to contact list id is not provided -->
                                          <filter xpath="get-property('operation','contactIds') != ''">
                                             <then>
                                                <!-- BEGIN: If more than one clicker is available construct contact ids array else single contact id value -->
                                                <filter xpath="get-property('operation', 'clickersCount') > 1">
                                                   <then>
                                                      <!-- If more than one clicker, construct clickers array by removing last comma -->
                                                      <property name="clickersArray" expression="fn:concat('[',fn:substring(get-property('operation','contactIds'),1,fn:string-length(get-property('operation','contactIds'))-1),']')" />
                                                      <property name="id" expression="fn:concat('{contact_ids:', get-property('clickersArray'), ', contact_list_id:', get-property('constantContact.contactListId'), '}')" />
                                                   </then>
                                                   <else>
                                                      <!-- If only one clicker remove last from single contact id -->
                                                      <property name="clickerId" expression="fn:concat(fn:substring(get-property('operation','contactIds'),1,fn:string-length(get-property('operation','contactIds'))-1),'')" />
                                                      <property name="id" expression="fn:concat('{contact_id:', get-property('clickerId'), ', contact_list_id:', get-property('constantContact.contactListId'), '}')" />
                                                   </else>
                                                </filter> <!-- END: If more than one clicker is available -->
                                             </then>
                                             <else>
                                                <property name="contactIds" value="{}" scope="operation" />
                                             </else>
                                          </filter> <!-- END: Check whether contact update is not failed -->
                                          <!-- Call the responseHandler template -->
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="constantcontact_addClickersToContactList" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                          <loopback />
                                       </then>
                                    </filter> <!-- END: To avoid execute until final clicker to reach -->
                                 </sequence>
                              </target>
                           </iterate> <!-- END: For each clicker -->
                        </else>
                     </filter> <!-- END: If user not provide contact list ID -->
                  </then>
                  <else>
                     <property name="id" value="{}" />
                     <!-- Response generator if no campaign clickers are available in provided campaign -->
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="constantcontact_retrieveClickers" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="Error" />
                        <with-param name="message" value="Clickers list is empty - No contacts to be processed" />
                     </call-template>
                     <loopback />
                  </else>
               </filter> <!-- END: Process only if clickers count is not zero -->
            </then>
            <else>
               <property name="id" value="{}" />
               <property name="status" value="Error" />
               <property name="message" expression="json-eval($.)" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="constantcontact_retrieveClickers" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>
               {
                  "Response":{
                     "process":"planyo_retrieveClickersAndCreateContactList",
                     "activityResponse":[$1]
                  }
               }
            </format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
</proxy>
Sample Request for retrieving a list of contacts from Constant Contact who have clicked on a link in the sent email campaign, and updating a contact list in Constant Contact
{ 
	"constantContactApiToken":"8c805eab-8970-47ce-b4d3-e72474be6d78",
	"constantContactApiKey":"vznzz39dtdgqfcu2d6c6njx7",
	"constantContactCampaignId":1120350187523,
	"constantContactContactListId":1687271079
}

Mandatory Parameters

Mandatory parameters : constantContactApiToken, constantContactApiKey, constantContactCampaignId, constantContactContactListId

Note

 The following are the parameter descriptions:

  • constantContactApiToken: The API Token of the Constant Contact account
  • constantContactApiKey: The API Key of the Constant Contact account
  • constantContactCampaignId: The ID of the sent campaign in Constant Contact from which the clickers will be retrieved
  • constantContactContactListId: The ID of the contact list in Constant Contact to which the clickers will be added