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/.

Deal Origination in PipelineDeals

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

Overview

The flow for deal origination is illustrated in the following diagram. The ESB connectors for Zoho CRM and MailChimp will be used to connect to each service.

Creating e-mail campaigns

  1. Retrieve the ID of the subscriber list using the provided list name from the MailChimp API using the listSubscriberLists operation.
  2. Create a draft campaign in the MailChimp API using the createDraftCampaign operation.
  3. Send the campaign through the MailChimp API using the sendCampaign operation.
MailChimp operations
Samples
Sample Proxy for creating an e-mail campaign in MailChimp and sending that to a specified subscriber's 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.
-->
<!--Create campaigns and send them to a subscribers' list via MailChimp-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="pipelinedeals_createCampaignAndSend" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <!-- mailChimp Properties -->
            <property name="mailchimp.apiUrl" expression="json-eval($.mailchimp.apiUrl)" />
            <property name="mailchimp.apiKey" expression="json-eval($.mailchimp.apiKey)" />
            <property name="mailchimp.listName" expression="json-eval($.mailchimp.listName)" />
            <property name="mailchimp.templateId" expression="json-eval($.mailchimp.templateId)" />
            <property name="mailchimp.campaignSubject" expression="json-eval($.mailchimp.campaignSubject)" />
            <property name="mailchimp.content" expression="json-eval($.mailchimp.content)" />
            <property name="mailchimp.fromEmail" expression="json-eval($.mailchimp.fromEmail)" />
            <property name="mailchimp.fromName" expression="json-eval($.mailchimp.fromName)" />
            
			<!-- Operation scoped properties -->
            <property name="responseString" value="" scope="operation" />
            <property name="activityName" value="pipelinedeals_createCampaignAndSend" scope="operation" />
           
		   <!-- Get the ID of the subscriber list using the provided list name. It is troublesome for the user to obtain the list ID in Mailchimp,
				as it cannot be done through the web application. Therefore the user is expected to provide the list name so the respective list ID can be obtained via the following call. -->
            <mailchimp.init>
                <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                <format>json</format>
            </mailchimp.init>
            <mailchimp.listSubscriberLists>
                <listName>{$ctx:mailchimp.listName}</listName>
            </mailchimp.listSubscriberLists>
            <sequence key="removeResponseHeaders" />
            <property name="mailchimp.listId" expression="json-eval($.data[0].id)" />
            
			<!-- START: Proceed to create the campaign in MailChimp only if the subscriber list ID could be retrieved using the name.
				When there are no lists matching the provided name, an empty array ([]) is returned by the Mailchimp API. -->
            <filter source="boolean(get-property('mailchimp.listId'))" regex="false">
                <then>
                    <!-- Failure case: Append an error message to be sent to the user. -->
                    <property name="id" expression="fn:concat('mailchimp_listName:', get-property('mailchimp.listName'))" />
                    <property name="errorResponse" expression="json-eval($)" />
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="mailchimp_getListIdFromListName" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="Skipped" />
                        <with-param name="message" value="{$ctx:errorResponse}" />
                    </call-template>
                </then>
                <else>
                    <!-- Construct the mailchimp 'options' parameter -->
                    <payloadFactory media-type="json">
                        <format>{
						"options": {
							"list_id": "$1",
							"subject": "$2",
							"from_email": "$3",
							"from_name": "$4",
							"to_name": "Subscriber",
							"template_id": "$5",
							"tracking": {
								"opens": true,
								"html_clicks": true,
								"text_clicks": true
							}
						}
					}</format>
                        <args>
                            <arg expression="get-property('mailchimp.listId')" />
                            <arg expression="get-property('mailchimp.campaignSubject')" />
                            <arg expression="get-property('mailchimp.fromEmail')" />
                            <arg expression="get-property('mailchimp.fromName')" />
                            <arg expression="get-property('mailchimp.templateId')" />
                        </args>
                    </payloadFactory>
                    <property name="mailchimp.options" expression="json-eval($.options)" />
                    
					<!-- Construct the mailchimp 'content' parameter where the HTML campaign parameters are specified. -->
                    <payloadFactory media-type="json">
                        <format>{
						"content": {
							"sections": {
								"companyName": "$1",
								"companyNameFooter": "$1",
								"title": "$2",
								"content": "$3"
							}
						}
					}</format>
                        <args>
                            <arg expression="get-property('mailchimp.fromName')" />
                            <arg expression="get-property('mailchimp.campaignSubject')" />
                            <arg expression="get-property('mailchimp.content')" />
                        </args>
                    </payloadFactory>
                    <property name="mailchimp.content" expression="json-eval($.content)" />
                    
					<!-- Create a draft campaign. -->
                    <mailchimp.init>
                        <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                        <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                        <format>json</format>
                    </mailchimp.init>
                    <mailchimp.createDraftCampaign>
                        <options>{$ctx:mailchimp.options}</options>
                        <content>{$ctx:mailchimp.content}</content>
                        <type>regular</type>
                    </mailchimp.createDraftCampaign>
                    <property name="mailchimp.campaignId" expression="json-eval($.id)" />
                    
					<!-- START: Proceed to send the campaign only if it is created successfully. -->
                    <filter source="boolean(get-property('mailchimp.campaignId'))" regex="false">
                        <then>
                            <!-- Failure case: Append an error message to be sent to the user. -->
                            <property name="id" value="{}" />
                            <property name="errorResponse" expression="json-eval($)" />
                            <call-template target="responseHandlerTemplate">
                                <with-param name="activity" value="mailchimp_createDraftCampaign" />
                                <with-param name="id" value="{$ctx:id}" />
                                <with-param name="status" value="Error" />
                                <with-param name="message" value="{$ctx:errorResponse}" />
                            </call-template>
                        </then>
                        <else>
                            <!-- Send the draft campaign. -->
                            <mailchimp.init>
                                <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                                <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                                <format>json</format>
                            </mailchimp.init>
                            <mailchimp.sendCampaign>
                                <campaignId>{$ctx:mailchimp.campaignId}</campaignId>
                            </mailchimp.sendCampaign>
                            <property name="mailchimp.complete" expression="json-eval($.complete)" />
                            <property name="id" expression="fn:concat('mailchimp_campaignId:', get-property('mailchimp.campaignId'))" />
                           
						   <!-- START: Build the response based on whether the campaign is successfully sent or not -->
                            <filter source="get-property('mailchimp.complete')" regex="true">
                                <then>
                                    <property name="status" value="Success" />
                                    <property name="message" value="The campaign has been created and successfully sent." />
                                </then>
                                <else>
                                    <property name="status" value="Error" />
                                    <property name="message" expression="json-eval($)" />
                                </else>
                            </filter>
                            <!-- Append message to be sent to the user. -->
                            <call-template target="responseHandlerTemplate">
                                <with-param name="activity" value="mailchimp_sendCampaign" />
                                <with-param name="id" value="{$ctx:id}" />
                                <with-param name="status" value="{$ctx:status}" />
                                <with-param name="message" value="{$ctx:message}" />
                            </call-template>
                        </else>
                    </filter>
                    <!-- END: Proceed to send the campaign only if it is created successfully. -->
                </else>
            </filter>
            <!-- END: Proceed to create the campaign in MailChimp only if the subscriber list ID could be retrieved using the name.
				When there are no lists matching the provided name, an empty array ([]) is returned by the Mailchimp API. -->
            
			<!-- Send the constructed response to the user. -->
            <payloadFactory media-type="json">
                <format>{
					"Response": {
						"process": "pipelinedeals_createCampaignAndSend",
						"activityResponse": [$1]
					}
				}</format>
                <args>
                    <arg expression="get-property('operation', 'responseString')" />
                </args>
            </payloadFactory>
            <respond />
        </inSequence>
        <outSequence />
    </target>
</proxy>
Sample Request for creating an e-mail campaign in MailChimp and sending that to a specified subscriber's list
{
	"mailchimp":{
		"apiUrl":"https://us9.api.mailchimp.com",
		"apiKey":"444e6b63ca5c81d2143d3a161226043b-us9",
		"listName":"Pipelinedeals Deal Subscribers",
		"templateId":"286169",
		"campaignSubject":"Car Security right at your DoorStep",
		"content":"Get a Security Alarm for your Car and get another absolutely free!",
		"fromEmail":"besafe.abdera@gmail.com",
		"fromName":"BeSafe Solutions"
	}
}

Note

 The following are the parameter descriptions:

  • mailchimp.listName: The name of the selected subscriber list.
  • mailchimp.templateId: The ID of the user-created template to generate the HTML content of the campaign.
  • mailchimp.campaignSubject: The the description goes as the subject of the MailChimp campaign.
  • mailchimp.fromEmail: The e-mail address of the sender of the campaign.
  • mailchimp.fromName: The name of the sender of the campaign.

Retrieving campaign clickers and creating deals

  1. Retrieve the given campaign details from the MailChimp API using the listCampaigns operation.
  2. Retrieve the clicks for the particular campaign from the MailChimp API using the listCampaignClicks operation.
  3. Retrieve the clickers for a particular URL using the listCampaignClickers operation.
  4. Create a person (if they do not exist) in the PipelineDeals API using the createPerson operation and create a deal (if it does not exist) for the retrieved clicker using the createDeal operation in the PipelineDeals API.
  5. Update the member note with the PipelineDeals person using the updateMember operation in the MailChimp API.
  6. Update the member note with the deal in the MailChimp API using the updateMember operation.
MailChimp operations
PipelineDeals operations
Samples
Sample Template for retrieving the ID of a custom field (identified by the provided label name) and setting it to the property 'pipelinedeals.customFieldString'
<?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 gets the ID of a custom field (identified by the provided label name) and sets it to the property 'pipelinedeals.customFieldString' -->
<template xmlns="http://ws.apache.org/ns/synapse" name="createContactsAndDeals">
    
	<!--Pipeline Deals parameters-->
    <parameter name="pipelinedeals.apiKey" description="Encrypted alphanumeric string to authenticate the pipelinedeals credentials." />
    <parameter name="pipelinedeals.apiUrl" description="The pipelinedeals API URL." />
    <parameter name="pipelinedeals.expectedCloseDate" description="The expected close date of the pipelineDeals deal." />
    <parameter name="pipelinedeals.value" description="The value of the deal of pipelineDeals." />
    <parameter name="pipelinedeals.dealStageId" description="The deal stage Id of 'FollowUp' stage in pipelineDeals." />
    <parameter name="pipelinedeals.sourceId" description="The deal source Id of 'mailchimp' source in pipelineDeals." />
    <parameter name="pipelinedeals.personEmail" description="The email of the person in pipelineDeals." />
    <parameter name="pipelinedeals.dealName" description="The name of the deal in pipelineDeals." />
    <parameter name="pipelinedeals.dealProbability" description="The probability of the deal in pipelineDeals." />
    <parameter name="pipelinedeals.personFName" description="The first name of the person in pipelineDeals." />
    <parameter name="pipelinedeals.personLName" description="The last name of the person in pipelineDeals." />
    <parameter name="pipelinedeals.dealSummary" description="Summary of the deal to be created." />
    
	<!-- Mailchimp parameters-->
    <parameter name="mailchimp.apiKey" description="Encrypted alphanumeric string to authenticate the mailchimp credentials." />
    <parameter name="mailchimp.apiUrl" description="The mailchimp API URL." />
    <parameter name="mailchimp.notes" description="The notes of the mailchimp memeber." />
    <parameter name="mailchimp.campaignId" description="The  ID of the mailchimp campaign." />
    <parameter name="mailchimp.memberId" description="The ID of the memeber who clicked a campaign link." />
    <parameter name="mailchimp.listId" description="The ID of the list which mailchimp memeber is belong." />
   
   <sequence>
        <property name="pipelinedeals.apiKey" expression="$func:pipelinedeals.apiKey" />
        <property name="pipelinedeals.apiUrl" expression="$func:pipelinedeals.apiUrl" />
        <property name="pipelinedeals.expectedCloseDate" expression="$func:pipelinedeals.expectedCloseDate" />
        <property name="pipelinedeals.value" expression="$func:pipelinedeals.value" />
        <property name="pipelinedeals.dealStageId" expression="$func:pipelinedeals.dealStageId" />
        <property name="pipelinedeals.sourceId" expression="$func:pipelinedeals.sourceId" />
        <property name="pipelinedeals.personEmail" expression="$func:pipelinedeals.personEmail" />
        <property name="pipelinedeals.dealName" expression="$func:pipelinedeals.dealName" />
        <property name="pipelinedeals.personFName" expression="$func:pipelinedeals.personFName" />
        <property name="pipelinedeals.personLName" expression="$func:pipelinedeals.personLName" />
        <property name="pipelinedeals.dealProbability" expression="$func:pipelinedeals.dealProbability" />
        <property name="pipelinedeals.dealSummary" expression="$func:pipelinedeals.dealSummary" />
        <property name="mailchimp.apiKey" expression="$func:mailchimp.apiKey" />
        <property name="mailchimp.apiUrl" expression="$func:mailchimp.apiUrl" />
        <property name="mailchimp.notes" expression="$func:mailchimp.notes" />
        <property name="mailchimp.memberId" expression="$func:mailchimp.memberId" />
        <property name="mailchimp.listId" expression="$func:mailchimp.listId" />
        <property name="mailchimp.campaignId" expression="$func:mailchimp.campaignId" />
        <property name="mailchimp.notes.contact" value="pipelineDeal people ID" />
        <property name="mailchimp.notes.deal" value="pipelineDeal deal ID" />
        <property name="pipelinedeals.personId" value="" />
        <property name="pipelinedeals.dealId" value="" />
        <!-- To retrieve deal ID and person ID from mailchimp members's notes if provided-->
        <script language="js">
			<![CDATA[
				var memberNotes = mc.getProperty('mailchimp.notes');
				var dealName = ''+mc.getProperty('pipelinedeals.dealName');
				var customFieldString = '';
				if(!new java.lang.String(memberNotes).startsWith('[')) {
					memberNotes = '['+memberNotes+']';
				}
				memberNotes = eval("(" + memberNotes + ")");
				
				if(memberNotes.length > 0){
					for(var i=0; i<memberNotes.length; i++){
						var memberNote = memberNotes[i];
						var noteName = ''+memberNote.note;
						if(new java.lang.String(noteName).startsWith('PipelineDeals Person ID')) {
							var peopleId = noteName.split(':')[1];
							mc.setProperty("pipelinedeals.personId",peopleId);
						}
						if(new java.lang.String(noteName).startsWith(dealName)) {
							var dealId = noteName.split(':')[1];
							mc.setProperty("pipelinedeals.dealId",dealId);
						}
					}
				}
			]]>
		</script>
        
		<!-- START: Proceed only if the deal ID doesn't exist in the  mailchimp notes -->
        <filter source="boolean(get-property('pipelinedeals.dealId'))" regex="false">
            <then>
                
				<!-- START: Proceed only if the person ID doesn't exist in the mailchimp notes -->
                <filter source="boolean(get-property('pipelinedeals.personId'))" regex="false">
                    <then>
                        <sequence key="removeResponseHeaders" />
                        <property name="DISABLE_CHUNKING" value="true" scope="axis2" />
                        
						<!-- Call pipelinedeals connector createPerson method to create a person -->
                        <pipelinedeals.init>
                            <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                            <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                        </pipelinedeals.init>
                        <pipelinedeals.createPerson>
                            <email>{$ctx:pipelinedeals.personEmail}</email>
                            <firstName>{$ctx:pipelinedeals.personFName}</firstName>
                            <lastName>{$ctx:pipelinedeals.personLName}</lastName>
                            <unsubscribed>false</unsubscribed>
                            <type>Contact</type>
                            <homeEmail>{$ctx:pipelinedeals.personEmail}</homeEmail>
                        </pipelinedeals.createPerson>
                        <property name="pipelinedeals.personId" expression="json-eval($.id)" />
                       
					   <!-- START: Proceed only if the the person is created successfully -->
                        <filter source="boolean(get-property('pipelinedeals.personId'))" regex="false">
                            <then>
                                <property name="id" expression="fn:concat('mailchimp_memberId:',get-property('mailchimp.memberId'))" />
                                <property name="status" value="Error" />
                                <property name="message" expression="json-eval($)" />
                                <!--Call the responseHandler template-->
                                <call-template target="responseHandlerTemplate">
                                    <with-param name="activity" value="pipelinedeals_createPerson" />
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="{$ctx:status}" />
                                    <with-param name="message" value="{$ctx:message}" />
                                </call-template>
                            </then>
                            <else>
                                <property name="id" expression="fn:concat('mailchimp_memberId:',get-property('mailchimp.memberId'),',pipelinedeals_personId:',get-property('pipelinedeals.personId'))" />
                                <property name="status" value="Success" />
                                <property name="message" value="A person has been created in pipeline deals." />
                                <!--Call the responseHandler template-->
                                <call-template target="responseHandlerTemplate">
                                    <with-param name="activity" value="pipelinedeals_createPerson" />
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="{$ctx:status}" />
                                    <with-param name="message" value="{$ctx:message}" />
                                </call-template>
                                <property name="mailchimp.memberNote" expression="fn:concat('PipelineDeals Person ID:',get-property('pipelinedeals.personId'))" />
                                
								<!-- Update member in mailchimp. -->
                                <payloadFactory media-type="json">
                                    <format>{
										"notes":[
											{
												"note":"$1"
											}
										]
									}</format>
                                    <args>
                                        <arg expression="get-property('mailchimp.memberNote')" />
                                    </args>
                                </payloadFactory>
								
                                <property name="mailchimp.memberNote" expression="json-eval($.notes)" />
                                
								<!-- Call mailchimp connector updateMember method to update memeber note with pipelinedeals person -->
                                <mailchimp.init>
                                    <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                                    <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                                    <format>json</format>
                                </mailchimp.init>
                                <mailchimp.updateMember>
                                    <listId>{$ctx:mailchimp.listId}</listId>
                                    <email>{$ctx:pipelinedeals.personEmail}</email>
                                    <mcNotes>{$ctx:mailchimp.memberNote}</mcNotes>
                                </mailchimp.updateMember>
                                <property name="mailchimp.email" expression="json-eval($.email)" />
                                
								<!-- Append an error message to the user only if the update fails. -->
                                <filter source="boolean(get-property('mailchimp.email'))" regex="false">
                                    <then>
                                        <property name="id" expression="fn:concat('pipelinedeals_personId:', get-property('pipelinedeals.personId'))" />
                                        <property name="message" expression="json-eval($)" />
                                        <call-template target="responseHandlerTemplate">
                                            <with-param name="activity" value="mailchimp_updateMember" />
                                            <with-param name="id" value="{$ctx:id}" />
                                            <with-param name="status" value="Error" />
                                            <with-param name="message" value="{$ctx:message}" />
                                        </call-template>
                                    </then>
                                </filter>
                            </else>
                        </filter>
                        <!-- END: Proceed only if the the person is created successfully -->
                    </then>
                </filter>
                <!-- END: Proceed only if the person ID doesn't exist in the mailchimp notes -->
                
				<!-- START: Proceed with deal creation only if the the person is created successfully -->
                <filter source="boolean(get-property('pipelinedeals.personId'))" regex="true">
                    <then>
                        <sequence key="removeResponseHeaders" />
                        <property name="DISABLE_CHUNKING" value="true" scope="axis2" />
                        <property name="pipelinedeals.newDealName" expression="fn:concat(get-property('pipelinedeals.dealName'),' [',get-property('pipelinedeals.personFName'),' ',get-property('pipelinedeals.personLName'),']')" />
                        
						<!-- Call pipelinedeals connector createDeal method to create a deal -->
                        <pipelinedeals.init>
                            <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                            <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                        </pipelinedeals.init>
                        <pipelinedeals.createDeal>
                            <name>{$ctx:pipelinedeals.newDealName}</name>
                            <primaryContactId>{$ctx:pipelinedeals.personId}</primaryContactId>
                            <probability>{$ctx:pipelinedeals.dealProbability}</probability>
                            <dealStageId>{$ctx:pipelinedeals.dealStageId}</dealStageId>
                            <sourceId>{$ctx:pipelinedeals.sourceId}</sourceId>
                            <expectedCloseDate>{$ctx:pipelinedeals.expectedCloseDate}</expectedCloseDate>
                            <isArchived>false</isArchived>
                            <value>{$ctx:pipelinedeals.value}</value>
                            <status>2</status>
                            <summary>{$ctx:pipelinedeals.dealSummary}</summary>
                        </pipelinedeals.createDeal>
                        <property name="pipelinedeals.dealId" expression="json-eval($.id)" />
                        
						<!-- START: Proceed with updating the mailchimp notes only if the deal is created successfully -->
                        <filter source="boolean(get-property('pipelinedeals.dealId'))" regex="false">
                            <then>
                                <property name="id" expression="fn:concat(',mailchimp_campaignId:',get-property('mailchimp.campaignId'),',pipelinedeals_personId:',get-property('pipelinedeals.personId'))" />
                                <property name="status" value="Error" />
                                <property name="message" expression="json-eval($)" />
                                <call-template target="responseHandlerTemplate">
                                    <with-param name="activity" value="pipelinedeals_createDeal" />
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="{$ctx:status}" />
                                    <with-param name="message" value="{$ctx:message}" />
                                </call-template>
                            </then>
                            <else>
                                <property name="id" expression="fn:concat('mailchimp_campaignId:',get-property('mailchimp.campaignId'),',pipelinedeals_personId:',get-property('pipelinedeals.personId'),',pipelinedeals_dealId:',get-property('pipelinedeals.dealId'))" />
                                <property name="status" value="Success" />
                                <property name="message" value="A deal has been created in pipeline deals." />
                                <call-template target="responseHandlerTemplate">
                                    <with-param name="activity" value="pipelinedeals_createDeal" />
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="{$ctx:status}" />
                                    <with-param name="message" value="{$ctx:message}" />
                                </call-template>
                                <property name="mailchimp.memberDealNote" expression="fn:concat(get-property('pipelinedeals.dealName'),':',get-property('pipelinedeals.dealId'))" />
                               
							   <!-- Update member in mailchimp. -->
                                <payloadFactory media-type="json">
                                    <format>{
										"notes":[
										{
											"note":"$1"
										}
									  ]
									}</format>
                                    <args>
                                        <arg expression="get-property('mailchimp.memberDealNote')" />
                                    </args>
                                </payloadFactory>
                                <property name="mailchimp.memberDealNote" expression="json-eval($.notes)" />
                                
								<!-- Call mailchimp connector updateMember method to update memeber note with pipelinedeals deal -->
                                <mailchimp.init>
                                    <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                                    <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                                    <format>json</format>
                                </mailchimp.init>
                                <mailchimp.updateMember>
                                    <listId>{$ctx:mailchimp.listId}</listId>
                                    <email>{$ctx:pipelinedeals.personEmail}</email>
                                    <mcNotes>{$ctx:mailchimp.memberDealNote}</mcNotes>
                                </mailchimp.updateMember>
                                <property name="mailchimp.email" expression="json-eval($.email)" />
                               
							   <!-- Append an error message to the user only if the update fails. -->
                                <filter source="boolean(get-property('mailchimp.email'))" regex="false">
                                    <then>
                                        <property name="id" expression="fn:concat('pipelinedeals_dealId:', get-property('pipelinedeals.dealId'))" />
                                        <property name="message" expression="json-eval($)" />
                                        <call-template target="responseHandlerTemplate">
                                            <with-param name="activity" value="mailchimp_updateMember" />
                                            <with-param name="id" value="{$ctx:id}" />
                                            <with-param name="status" value="Error" />
                                            <with-param name="message" value="{$ctx:message}" />
                                        </call-template>
                                    </then>
                                </filter>
                            </else>
                        </filter>
                        <!-- END: Proceed with updating the mailchimp notes only if the deal is created successfully -->
                    </then>
                </filter>
                <!-- END: Proceed with deal creation only if the the person is created successfully -->
            </then>
        </filter>
        <!-- END: Proceed only if the deal ID is exist in the notes -->
    </sequence>
</template>
Sample Proxy for retrieving the campaign clickers and creating deals for them in PipelineDeals based on the link probabilities sent via the 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.
-->
<!--Retrieve campaign clickers from mailchimp and create deals for them in Pipeline Deals -->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="pipelinedeals_retrieveClickersAndCreateDeals" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <!-- MailChimp Properties -->
            <property name="mailchimp.apiUrl" expression="json-eval($.mailchimp.apiUrl)" />
            <property name="mailchimp.apiKey" expression="json-eval($.mailchimp.apiKey)" />
            <property name="mailchimp.campaignId" expression="json-eval($.mailchimp.campaignId)" />
            <property name="mailchimp.highUrl" expression="json-eval($.mailchimp.high.url)" />
            <property name="mailchimp.lowUrl" expression="json-eval($.mailchimp.low.url)" />
            <property name="mailchimp.highProbability" expression="json-eval($.mailchimp.high.probability)" />
            <property name="mailchimp.lowProbability" expression="json-eval($.mailchimp.low.probability)" />
            
			<!-- pipelineDeals Properties -->
            <property name="pipelinedeals.apiUrl" value="http://api.pipelinedeals.com" />
            <property name="pipelinedeals.apiKey" expression="json-eval($.pipelinedeals.apiKey)" />
            <property name="pipelinedeals.expectedCloseDate" expression="json-eval($.pipelinedeals.expectedCloseDate)" />
            <property name="pipelinedeals.value" expression="json-eval($.pipelinedeals.value)" />
            <property name="pipelinedeals.summary" expression="json-eval($.pipelinedeals.summary)" />
            
			<!-- Operation scoped properties -->
            <property name="responseString" value="" scope="operation" />
            <property name="activityName" value="pipelinedeals_retrieveClickersAndCreateDeals" scope="operation" />
            <sequence key="removeResponseHeaders" />
            
			<!-- Calling retrieveClickersAndCreateDeals-verifyPrerequisites sequence to get deal stages-->
            <sequence key="retrieveClickersAndCreateDeals-verifyPrerequisites" />
            
			<!--Call mailchimp connector listCampaigns method to get the given campaign details -->
            <mailchimp.init>
                <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                <format>json</format>
            </mailchimp.init>
            <mailchimp.listCampaigns>
                <campaignId>{$ctx:mailchimp.campaignId}</campaignId>
            </mailchimp.listCampaigns>
            <sequence key="removeResponseHeaders" />
            <property name="mailchimp.responseCampaignTotal" expression="json-eval($.total)" />
            
			<!--Process only if the the particular campaign details retrieved-->
            <filter xpath="get-property('mailchimp.responseCampaignTotal') != 1">
                <then>
                    <!-- Failure case: Append an error message to be sent to the user. -->
                    <property name="id" expression="fn:concat('mailchimp_campaignId:', get-property('mailchimp.campaignId'))" />
                    <property name="errorResponse" expression="json-eval($)" />
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="mailchimp_getCampaign" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="Skipped" />
                        <with-param name="message" value="The given campaign ID is not valid" />
                    </call-template>
                    <loopback />
                </then>
                <else>
                    <property name="mailchimp.responseCampaignId" expression="json-eval($.data[0].id)" />
                    <property name="mailchimp.campaignName" expression="json-eval($.data[0].title)" />
                    <property name="mailchimp.companyName" expression="json-eval($.data[0].from_email)" />
            
					<!--Call mailchimp connector listCampaignClicks method to get the clicks for a particular campaign -->
                    <mailchimp.init>
                        <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                        <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                        <format>json</format>
                    </mailchimp.init>
                    <mailchimp.listCampaignClicks>
                        <campaignId>{$ctx:mailchimp.campaignId}</campaignId>
                    </mailchimp.listCampaignClicks>
                    <sequence key="removeResponseHeaders" />
                    <property name="mailchimp.clicks" expression="json-eval($.total)" />
                    
					<!-- START: Proceed only if there are clicks for the campaign. -->
                    <filter xpath="get-property('mailchimp.clicks') = '[]'">
                        <then>
                            <!-- Failure case: Append an error message to be sent to the user. -->
                            <property name="id" expression="fn:concat('mailchimp_campaignId:', get-property('mailchimp.campaignId'))" />
                            <call-template target="responseHandlerTemplate">
                                <with-param name="activity" value="mailchimp_getClicks" />
                                <with-param name="id" value="{$ctx:id}" />
                                <with-param name="status" value="Skipped" />
                                <with-param name="message" value="No clicks for the campaign." />
                            </call-template>
                            <loopback />
                        </then>
                        <else>
                            <!--To retrieve the track IDs of the urls being clicked seperately -->
                            <script language="js">
								<![CDATA[
									var clicks = eval("(" + mc.getProperty('mailchimp.clicks') + ")");
									var highLink = mc.getProperty('mailchimp.highUrl');
									var lowLink = mc.getProperty('mailchimp.lowUrl');
								    for(var i=0; i<clicks.length; i++){
										var click = clicks[i];
										if(click.url == highLink) {
											var hTrackId = ''+click.tid;
											mc.setProperty('mailchimp.highTrackId', hTrackId);
										}
										if(click.url == lowLink) {
											var lTrackId = ''+click.tid;
											mc.setProperty('mailchimp.lowTrackId', lTrackId);
										}
									}
								]]>
							</script>
                    
							<!-- START: Proceed only if the link with higher probability is found -->
                            <filter source="boolean(get-property('mailchimp.highTrackId'))" regex="false">
                                <then>
                                    <property name="id" expression="fn:concat('mailchimp_campaignId:', get-property('mailchimp.campaignId'))" />
                                    <property name="message" expression="fn:concat('The link [', get-property('mailchimp.highUrl'),'] is not valid')" />
                                    
									<!-- Failure case: Append an error message to be sent to the user. -->
                                    <property name="errorResponse" expression="json-eval($)" />
                                    <call-template target="responseHandlerTemplate">
                                        <with-param name="activity" value="mailchimp_getCampaignClicks" />
                                        <with-param name="id" value="{$ctx:id}" />
                                        <with-param name="status" value="Skipped" />
                                        <with-param name="message" value="{$ctx:message}" />
                                    </call-template>
                                    
									<!-- Calling mailchimp-retrieveLowProbabilityClickerSeq sequence to create deals for low probability link-->
                                    <sequence key="mailchimp-retrieveLowProbabilityClickerSeq" />
                                    <loopback />
                                </then>
                                <else>
                                    <!--Call mailchimp connector listCampaignClickers method to get the clickers for a particular Url -->
                                    <mailchimp.init>
                                        <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                                        <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                                        <format>json</format>
                                    </mailchimp.init>
                                    <mailchimp.listCampaignClickers>
                                        <campaignId>{$ctx:mailchimp.campaignId}</campaignId>
                                        <trackingid>{$ctx:mailchimp.highTrackId}</trackingid>
                                    </mailchimp.listCampaignClickers>
                                    
									<filter source="$axis2:HTTP_SC" regex="200">
                                        <then>
                                            <property name="clickerIndex" expression="0" scope="operation" />
                                            <property name="clickerCount" expression="count(//data)" scope="operation" />
                                            
											<!-- START: Proceed only if there are clickers for the high probability url -->
                                            <filter xpath="get-property('operation', 'clickerCount') = 0">
                                                <then>
                                                    <property name="id" expression="fn:concat('mailchimp_campaignId:',get-property('mailchimp.campaignId'),',mailchimp_highUrlId:',get-property('mailchimp.highTrackId'))" />
                                                    <property name="status" value="Skipped" />
                                                    <property name="message" value="No clickers for the link." />
                                                    <call-template target="responseHandlerTemplate">
                                                        <with-param name="id" value="{$ctx:id}" />
                                                        <with-param name="activity" value="mailchimp_getClickers" />
                                                        <with-param name="status" value="{$ctx:status}" />
                                                        <with-param name="message" value="{$ctx:message}" />
                                                    </call-template>
                                                   
												   <!-- Calling mailchimp-retrieveLowProbabilityClickerSeq sequence to create deals for low probability link-->
                                                    <sequence key="mailchimp-retrieveLowProbabilityClickerSeq" />
                                                    <loopback />
                                                </then>
                                                <else>
                                                    
													<!--BEGIN:FOR EACH clicker -->
                                                    <iterate continueParent="false" id="clickers" expression="//data" sequential="true">
                                                        <target>
                                                            <sequence>
                                                                <property name="mailchimp.memberId" expression="json-eval($.data.member.id)" />
                                                                <property name="mailchimp.memberNotes" expression="json-eval($.data.member.notes)" />
                                                                <property name="mailchimp.memberEmail" expression="json-eval($.data.member.email)" />
                                                                <property name="mailchimp.listId" expression="json-eval($.data.member.list_id)" />
                                                                <property name="mailchimp.memberFName" expression="json-eval($.data.member.merges.FNAME)" />
                                                                <property name="mailchimp.memberLName" expression="json-eval($.data.member.merges.LNAME)" />
                                                                
																<!-- Call createContactsAndDeals template to create people and deals -->
                                                                <call-template target="createContactsAndDeals">
                                                                    <with-param name="mailchimp.apiKey" value="{$ctx:mailchimp.apiKey}" />
                                                                    <with-param name="mailchimp.apiUrl" value="{$ctx:mailchimp.apiUrl}" />
                                                                    <with-param name="mailchimp.notes" value="{$ctx:mailchimp.memberNotes}" />
                                                                    <with-param name="mailchimp.memberId" value="{$ctx:mailchimp.memberId}" />
                                                                    <with-param name="mailchimp.listId" value="{$ctx:mailchimp.listId}" />
                                                                    <with-param name="mailchimp.campaignId" value="{$ctx:mailchimp.responseCampaignId}" />
                                                                    <with-param name="pipelinedeals.apiKey" value="{$ctx:pipelinedeals.apiKey}" />
                                                                    <with-param name="pipelinedeals.apiUrl" value="{$ctx:pipelinedeals.apiUrl}" />
                                                                    <with-param name="pipelinedeals.personEmail" value="{$ctx:mailchimp.memberEmail}" />
                                                                    <with-param name="pipelinedeals.dealName" value="{$ctx:mailchimp.campaignName}" />
                                                                    <with-param name="pipelinedeals.dealProbability" value="{$ctx:mailchimp.highProbability}" />
                                                                    <with-param name="pipelinedeals.personFName" value="{$ctx:mailchimp.memberFName}" />
                                                                    <with-param name="pipelinedeals.personLName" value="{$ctx:mailchimp.memberLName}" />
                                                                    <with-param name="pipelinedeals.expectedCloseDate" value="{$ctx:pipelinedeals.expectedCloseDate}" />
                                                                    <with-param name="pipelinedeals.value" value="{$ctx:pipelinedeals.value}" />
                                                                    <with-param name="pipelinedeals.dealStageId" value="{$ctx:pipelinedeals.followupStageId}" />
                                                                    <with-param name="pipelinedeals.dealSummary" value="{$ctx:pipelinedeals.summary}" />
                                                                    <with-param name="pipelinedeals.sourceId" value="{$ctx:pipelinedeals.mailchimpDealSourceId}" />
                                                                </call-template>
                                                                
																<property name="clickerIndex" expression="get-property('operation','clickerIndex') + 1" scope="operation" />
                                                                
																<filter xpath="get-property('operation','clickerIndex') = get-property('operation', 'clickerCount')">
                                                                    <then>
                                                                        <!-- Calling mailchimp-retrieveLowProbabilityClickerSeq sequence to create deals for low probability link-->
                                                                        <sequence key="mailchimp-retrieveLowProbabilityClickerSeq" />
                                                                        <loopback />
                                                                    </then>
                                                                </filter>
                                                            </sequence>
                                                        </target>
                                                    </iterate>
                                                    <!--END:FOR EACH clicker -->
                                                </else>
                                            </filter>
                                            <!-- END: Proceed only if there are clickers for the high probability url -->
                                        </then>
                                        <else>
                                            <!-- Calling mailchimp-retrieveLowProbabilityClickerSeq sequence to create deals for low probability link-->
                                            <sequence key="mailchimp-retrieveLowProbabilityClickerSeq" />
                                            <loopback />
                                        </else>
                                    </filter>
                                </else>
                            </filter>
                            <!-- END: Proceed only if the link with higher probability is found -->
                        </else>
                    </filter>
                    <!-- END: Proceed only if there are clicks for the campaign. -->
                </else>
            </filter>
        </inSequence>
        <outSequence>
            <filter source="boolean(get-property('operation', 'responseString'))" regex="false">
                <then>
                    <payloadFactory media-type="json">
                        <format>{
							 "Response":{
								"process":"pipelinedeals_retrieveClickersAndCreateDeals",
								"activityResponse":"All deals have been created for the campaign already."
							 }
						}</format>
                    </payloadFactory>
                </then>
                <else>
                    <payloadFactory media-type="json">
                        <format>{
							 "Response":{
								"process":"pipelinedeals_retrieveClickersAndCreateDeals",
								"activityResponse":[$1]
							 }
						}</format>
                        <args>
                            <arg expression="get-property('operation', 'responseString')" />
                        </args>
                    </payloadFactory>
                </else>
            </filter>
            <respond />
        </outSequence>
    </target>
</proxy>
Sample Request for retrieving the campaign clickers and creating deals for them in PipelineDeals based on the link probabilities sent via the campaign
{
    "mailchimp": {
        "apiUrl": "https://us9.api.mailchimp.com",
        "apiKey": "444e6b63ca5c81d2143d3a161226043b-us9",
        "campaignId": "ccd61f6942",
        "low": {
            "url": "http://www.necotechnologylanka.com/home-security-systems.htm",
            "probability": "40"
        },
        "high": {
            "url": "http://www.necotechnologylanka.com/contact_us.htm",
            "probability": "60"
        }
    },
    "pipelinedeals": {
        "apiKey": "TNHIHSDN0ZhDFFFieJ2",
        "expectedCloseDate":"2015-07-31",        
        "summary":"Car security alarm system.",
        "value":"1200"
    }
}

Note

 The following are the parameter descriptions:

  • mailchimp.campaignId : The ID of the campaign to which the deals are going to be created in PipelineDeals. 
  • mailchimp.low : An object containing the low probability URL information.
    • url : The URL which is considered as the link with low probability.
    • probability : The probability associated with the above link.
  • mailchimp.high : An object containing the high probability URL information.
    • url : The URL which is considered as the link with high probability.
    • probability: The probability associated with the above link.
  • pipelinedeals.expectedCloseDate : The expected close date of the PipelineDeals deal.
  • pipelinedeals.summary : Summary of the deal associated with the campaign.

 Clickers should have the first name and last name values set in MailChimp to be properly created in PipelineDeals.

Retrieving potentials and creating deals

  1. Retrieve potentials which are in the 'Follow up' stage from the Zoho CRM API using the getRecords operation.
  2. Retrieve the details of the account in Zoho CRM to which the potential belongs using the getRecordsById operation in the Zoho CRM API.
  3. Create a company in the PipelineDeals API using the createCompany operation if it does not exist.
  4. Update the Zoho CRM account with the PipelineDeals company ID using the updateRecords operation in the Zoho CRM API.
  5. Create a person based on the Zoho CRM contact in the PipelineDeals API using the createPerson operation if it does not exist.
  6. Update the Zoho CRM contact with the PipelineDeals person ID using the updateRecords in the Zoho CRM API.
  7. Create a deal based on the Zoho CRM potential using the createDeal operation in the PipelineDeals API.
  8. Update the Zoho CRM potential with the PipelineDeals deal ID using the updateRecords operation in the Zoho CRM API.
Zoho CRM operations
PipelineDeals operations
Samples
Sample Proxy for retrieving potentials in the 'follow-up' stage from Zoho CRM and creating them as deals in PipelindeDeals (only the potentials which are created/modified on the current day)
<?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.
-->
<!-- The proxy retrieves new potentials from ZohoCRM and creates them as deals in PipelineDeals Account.
	 If the companies and contacts associated with the deal are not found in PipelineDeals Account, they're created as well. -->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="pipelinedeals_retrievePotentialsAndCreateDeals" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <!-- ZohoCrm Properties -->
            <property name="zohocrm.apiUrl" value="https://crm.zoho.com" />
            <property name="zohocrm.accessToken" expression="json-eval($.zohocrm.accessToken)" />
			
            <!-- PipelineDeals Properties -->
            <property name="pipelinedeals.apiUrl" value="https://api.pipelinedeals.com" />
            <property name="pipelinedeals.apiKey" expression="json-eval($.pipelinedeals.apiKey)" />
			
            <!-- Common properties -->
            <property name="id.empty" value="{}" />
            <property name="responseString" value="" scope="operation" />
            <property name="activityName" value="pipelinedeals_retrievePotentialsAndCreateDeals" scope="operation" />
			
            <!-- The sequence will verify whether the prerequisites are met to proceed with the case. It will terminate the process otherwise. -->
            <sequence key="retrievePotentialsAndCreateDeals-verifyPrerequisites" />
			
            <!-- Get the start of the current day as the 'lastModifiedTime'-->
            <script language="js">
				<![CDATA[
					mc.setProperty('zohocrm.lastModifiedTime', new java.text.SimpleDateFormat("yyyy-MM-dd '00:00:00'").format(new java.util.Date()));
				]]>
			</script>
			
            <!-- Retrieve all new potentials which are created/modified on the current day of execution. -->
            <zohocrm.init>
                <scope>crmapi</scope>
                <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
            </zohocrm.init>
            <zohocrm.getRecords>
                <moduleType>Potentials</moduleType>
                <selectColumns>All</selectColumns>
                <lastModifiedTime>{$ctx:zohocrm.lastModifiedTime}</lastModifiedTime>
            </zohocrm.getRecords>
            <sequence key="removeResponseHeaders" />
			
            <!--Retrieving the response from the result -->
            <property name="zohocrm.response" expression="json-eval($.response.result)" />
			
            <!-- START: Error case: If the response is having errors then display the error message given by the API. -->
            <filter source="boolean(get-property('zohocrm.response'))" regex="false">
                <then>
                    <property name="errorResponse" expression="json-eval($)" />
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="zohocrm_getPotentialsOfTheDay" />
                        <with-param name="id" value="{$ctx:id.empty}" />
                        <with-param name="status" value="Error" />
                        <with-param name="message" value="{$ctx:errorResponse}" />
                    </call-template>
                    <loopback />
                </then>
                <else>
                    <property name="zohoCrm.potentialCount" expression="count(//row)" />
                    <property name="zohoCrm.potentialIndex" expression="0" scope="operation" />
					
                    <!-- START: Proceed only if there any potentials created/modified on the current day of execution. -->
                    <filter source="get-property('zohoCrm.potentialCount')" regex="0.0">
                        <then>
                            <call-template target="responseHandlerTemplate">
                                <with-param name="activity" value="zohocrm_getRecords" />
                                <with-param name="id" value="{$ctx:id.empty}" />
                                <with-param name="status" value="Error" />
                                <with-param name="message" value="There are no potentials created today." />
                            </call-template>
                            <loopback />
                        </then>
                        <else>
                            <property name="dealsInFollowUp" expression="0" scope="operation" />
							
                            <!-- BEGIN: FOR EACH potential -->
                            <iterate continueParent="false" id="casePotential" expression="//row" sequential="true">
                                <target>
                                    <sequence>
                                        <property name="potentialAttributes" expression="json-eval($.row.FL)" />
                                        <property name="zohocrm.potential.potentialId" expression="//content[../val/text() = 'POTENTIALID']" />
                                        <property name="zohocrm.potential.accountId" expression="//content[../val/text() = 'ACCOUNTID']" />
                                        <property name="zohocrm.potential.contactId" expression="//content[../val/text() = 'CONTACTID']" />
                                        <property name="zohocrm.potential.dealId" expression="//content[../val/text() = 'PipelineDeals Deal ID']" />
                                        <property name="zohocrm.potential.stage" expression="//content[../val/text() = 'Stage']" />
                                        <property name="zohocrm.potential.name" expression="//content[../val/text() = 'Potential Name']" />
                                        <property name="zohocrm.potential.description" expression="//content[../val/text() = 'Description']" />
                                        <property name="zohocrm.potential.probability" expression="//content[../val/text() = 'Probability']" />
                                        <property name="zohocrm.potential.amount" expression="//content[../val/text() = 'Amount']" />
                                        <property name="zohocrm.potential.expectedCloseDate" expression="//content[../val/text() = 'Closing Date']" />
                                        
										<!-- START: Proceed to create the deal only if it is not created already. -->
                                        <filter source="boolean(get-property('zohocrm.potential.dealId'))" regex="false">
                                            <then>
                                                <!-- START: Proceed only if the potential is in 'Follow-Up' stage. -->
                                                <filter source="fn:lower-case(get-property('zohocrm.potential.stage'))" regex="follow-up">
                                                    <then>
                                                        <property name="dealsInFollowUp" expression="get-property('operation', 'dealsInFollowUp') + 1" scope="operation" />
                                                        
														<!-- Timeout of 5s have been added to prevent duplication of companies and people in PipelineDeals API. -->
                                                        <script language="js">
															<![CDATA[
																java.lang.Thread.sleep(5000);
															]]>
														</script>
                                                        
														<!-- Get the details of the account in ZohoCRM to which the potential belongs. -->
                                                        <zohocrm.init>
                                                            <scope>crmapi</scope>
                                                            <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                                                            <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                                                        </zohocrm.init>
                                                        <zohocrm.getRecordsById>
                                                            <id>{$ctx:zohocrm.potential.accountId}</id>
                                                            <moduleType>Accounts</moduleType>
                                                        </zohocrm.getRecordsById>
                                                        <sequence key="removeResponseHeaders" />
														
                                                        <property name="zohocrm.potential.companyId" expression="//content[../val/text() = 'PipelineDeals Company ID']" />
                                                        <property name="zohocrm.account.name" expression="//content[../val/text() = 'Account Name']" />
                                                        <property name="zohocrm.account.phone" expression="//content[../val/text() = 'Phone']" />
                                                        <property name="zohocrm.account.fax" expression="//content[../val/text() = 'Fax']" />
                                                        <property name="zohocrm.account.website" expression="//content[../val/text() = 'Website']" />
                                                        <property name="zohocrm.account.email" expression="//content[../val/text() = 'Work Email']" />
                                                        <property name="zohocrm.account.billingStreet" expression="//content[../val/text() = 'Billing Street']" />
                                                        <property name="zohocrm.account.billingCity" expression="//content[../val/text() = 'Billing City']" />
                                                        <property name="zohocrm.account.billingState" expression="//content[../val/text() = 'Billing State']" />
                                                        <property name="zohocrm.account.description" expression="//content[../val/text() = 'Description']" />
                                                        <property name="zohocrm.account.billingCode" expression="//content[../val/text() = 'Billing Code']" />
                                                        <property name="zohocrm.account.billingCountry" expression="//content[../val/text() = 'Billing Country']" />
                                                        
														<!-- START: Proceed to create the company in Pipeline Deals (for the ZohoCRM account) if not already created. -->
                                                        <filter source="boolean(get-property('zohocrm.potential.companyId'))" regex="false">
                                                            <then>
                                                                <property name="messageType" value="application/json" scope="axis2" />
                                                                
																<!-- Create a company based on the ZohoCRM Account. -->
                                                                <pipelinedeals.init>
                                                                    <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                                                                    <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                                                                    <attributes>id</attributes>
                                                                </pipelinedeals.init>
                                                                <pipelinedeals.createCompany>
                                                                    <companyName>{$ctx:zohocrm.account.name}</companyName>
                                                                    <description>{$ctx:zohocrm.account.description}</description>
                                                                    <email>{$ctx:zohocrm.account.email}</email>
                                                                    <website>{$ctx:zohocrm.account.website}</website>
                                                                    <fax>{$ctx:zohocrm.account.fax}</fax>
                                                                    <address1>{$ctx:zohocrm.account.billingStreet}</address1>
                                                                    <city>{$ctx:zohocrm.account.billingCity}</city>
                                                                    <state>{$ctx:zohocrm.account.billingState}</state>
                                                                    <postalCode>{$ctx:zohocrm.account.billingCode}</postalCode>
                                                                    <country>{$ctx:zohocrm.account.billingCountry}</country>
                                                                    <phone1>{$ctx:zohocrm.account.phone}</phone1>
                                                                    <phone1Description>Work Phone</phone1Description>
                                                                </pipelinedeals.createCompany>
                                                                <sequence key="removeResponseHeaders" />
                                                                
																<property name="zohocrm.potential.companyId" expression="json-eval($.id)" />
                                                                
																<!-- START: Proceed to update the custom field only if the company has been created successfully. -->
                                                                <filter source="boolean(get-property('zohocrm.potential.companyId'))" regex="true">
                                                                    <then>
                                                                        <property name="id" expression="fn:concat('zohocrm_accountId:', get-property('zohocrm.potential.accountId'), ',pipelinedeals_companyId:', get-property('zohocrm.potential.companyId'))" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createCompany" />
                                                                            <with-param name="id" value="{$ctx:id}" />
                                                                            <with-param name="status" value="Success" />
                                                                            <with-param name="message" value="Company has been created successfully." />
                                                                        </call-template>
																		
                                                                        <!--Update the PipelineDeals company ID in the zohoCrm account in the custom field 'PipelineDeals Company ID' -->
                                                                        <script language="js">
																			<![CDATA[
																				//constructing the xml data in order to update the account in ZohoCrm								
																				var companyId = mc.getProperty('zohocrm.potential.companyId');								
																				var xmlData="<Accounts> <row no=\"1\"> <FL val=\"PipelineDeals Company ID\">"+companyId+"</FL> </row> </Accounts>";															
																				mc.setProperty('zohocrm.xmlData', xmlData);
																			]]>
																		</script>
																		
                                                                        <!-- Update the ZohoCRM account with PipelineDeals Company ID. -->
                                                                        <zohocrm.init>
                                                                            <scope>crmapi</scope>
                                                                            <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                                                                            <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                                                                        </zohocrm.init>
                                                                        <zohocrm.updateRecords>
                                                                            <moduleType>Accounts</moduleType>
                                                                            <id>{$ctx:zohocrm.potential.accountId}</id>
                                                                            <xmlData>{$ctx:zohocrm.xmlData}</xmlData>
                                                                        </zohocrm.updateRecords>
                                                                        <sequence key="removeResponseHeaders" />
																		
                                                                        <property name="zohocrm.accountId" expression="//content[../val/text() = 'Id']" />
                                                                        
																		<!-- Append an error message to the user only if the update fails. -->
                                                                        <filter source="boolean(get-property('zohocrm.accountId'))" regex="false">
                                                                            <then>
                                                                                <property name="id" expression="fn:concat('zohocrm_accountId:', get-property('zohocrm.potential.accountId'), ',pipelinedeals_companyId:', get-property('zohocrm.potential.companyId'))" />
                                                                                <property name="message" expression="json-eval($)" />
                                                                                <call-template target="responseHandlerTemplate">
                                                                                    <with-param name="activity" value="zohocrm_updateAccount" />
                                                                                    <with-param name="id" value="{$ctx:id}" />
                                                                                    <with-param name="status" value="Error" />
                                                                                    <with-param name="message" value="{$ctx:message}" />
                                                                                </call-template>
                                                                            </then>
                                                                        </filter>
                                                                    </then>
                                                                    <else>
                                                                        <property name="message" expression="json-eval($)" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createCompany" />
                                                                            <with-param name="id" value="{$ctx:id.empty}" />
                                                                            <with-param name="status" value="Error" />
                                                                            <with-param name="message" value="{$ctx:message}" />
                                                                        </call-template>
                                                                    </else>
                                                                </filter>
                                                                <!-- END: Proceed to update the custom field only if the company has been created successfully. -->
                                                            </then>
                                                        </filter>
                                                        <!-- END: Proceed to create the company in Pipeline Deals (for the ZohoCRM account) if not already created. -->
														
                                                        <!-- Get the details of the contact in ZohoCRM to which the potential belongs. -->
                                                        <zohocrm.init>
                                                            <scope>crmapi</scope>
                                                            <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                                                            <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                                                        </zohocrm.init>
                                                        <zohocrm.getRecordsById>
                                                            <id>{$ctx:zohocrm.potential.contactId}</id>
                                                            <moduleType>Contacts</moduleType>
                                                        </zohocrm.getRecordsById>
                                                        <sequence key="removeResponseHeaders" />
														
                                                        <property name="zohocrm.potential.personId" expression="//content[../val/text() = 'PipelineDeals Person ID']" />
														
                                                        <!-- START: Proceed to create the person in Pipeline Deals (for the ZohoCRM contact) if not already created. -->
                                                        <filter source="boolean(get-property('zohocrm.potential.personId'))" regex="false">
                                                            <then>
                                                                <property name="zohocrm.contact.firstName" expression="//content[../val/text() = 'First Name']" />
                                                                <property name="zohocrm.contact.lastName" expression="//content[../val/text() = 'Last Name']" />
                                                                <property name="zohocrm.contact.name" expression="fn:concat(get-property('zohocrm.contact.firstName'), ' ', get-property('zohocrm.contact.lastName'))" />
                                                                <property name="zohocrm.contact.phone" expression="//content[../val/text() = 'Phone']" />
                                                                <property name="zohocrm.contact.description" expression="//content[../val/text() = 'Description']" />
                                                                <property name="zohocrm.contact.mobile" expression="//content[../val/text() = 'Mobile']" />
                                                                <property name="zohocrm.contact.title" expression="//content[../val/text() = 'Title']" />
                                                                <property name="zohocrm.contact.email" expression="//content[../val/text() = 'Email']" />
                                                                <property name="zohocrm.contact.mailingStreet" expression="//content[../val/text() = 'Mailing Street']" />
                                                                <property name="zohocrm.contact.mailingCity" expression="//content[../val/text() = 'Mailing City']" />
                                                                <property name="zohocrm.contact.mailingState" expression="//content[../val/text() = 'Mailing State']" />
                                                                <property name="zohocrm.contact.mailingZip" expression="//content[../val/text() = 'Mailing Zip']" />
                                                                <property name="zohocrm.contact.mailingCountry" expression="//content[../val/text() = 'Mailing Country']" />
                                                                <property name="zohocrm.contact.otherStreet" expression="//content[../val/text() = 'Other Street']" />
                                                                <property name="zohocrm.contact.otherCity" expression="//content[../val/text() = 'Other City']" />
                                                                <property name="zohocrm.contact.otherState" expression="//content[../val/text() = 'Other State']" />
                                                                <property name="zohocrm.contact.otherZip" expression="//content[../val/text() = 'Other Zip']" />
                                                                <property name="zohocrm.contact.otherCountry" expression="//content[../val/text() = 'Other Country']" />
                                                                
																<!-- Create a person based on the ZohoCRM contact. -->
                                                                <property name="messageType" value="application/json" scope="axis2" />
                                                                <pipelinedeals.init>
                                                                    <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                                                                    <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                                                                    <attributes>id</attributes>
                                                                </pipelinedeals.init>
                                                                <pipelinedeals.createPerson>
                                                                    <fullName>{$ctx:zohocrm.contact.name}</fullName>
                                                                    <firstName>{$ctx:zohocrm.contact.firstName}</firstName>
                                                                    <lastName>{$ctx:zohocrm.contact.lastName}</lastName>
                                                                    <summary>{$ctx:zohocrm.contact.description}</summary>
                                                                    <phone>{$ctx:zohocrm.contact.phone}</phone>
                                                                    <mobile>{$ctx:zohocrm.contact.mobile}</mobile>
                                                                    <position>{$ctx:zohocrm.contact.title}</position>
                                                                    <website>{$ctx:zohocrm.account.website}</website>
                                                                    <email>{$ctx:zohocrm.contact.email}</email>
                                                                    <companyId>{$ctx:zohocrm.potential.companyId}</companyId>
                                                                    <type>Contact</type>
                                                                    <workAddress>{$ctx:zohocrm.contact.mailingStreet}</workAddress>
                                                                    <secondaryWorkAddress>{$ctx:secondaryWorkAddress}</secondaryWorkAddress>
                                                                    <workCity>{$ctx:zohocrm.contact.mailingCity}</workCity>
                                                                    <workState>{$ctx:zohocrm.contact.mailingState}</workState>
                                                                    <workCountry>{$ctx:zohocrm.contact.mailingCountry}</workCountry>
                                                                    <workPostalCode>{$ctx:zohocrm.contact.mailingZip}</workPostalCode>
                                                                    <homeAddress>{$ctx:zohocrm.contact.otherStreet}</homeAddress>
                                                                    <secondaryHomeAddress>{$ctx:secondaryHomeAddress}</secondaryHomeAddress>
                                                                    <homeCity>{$ctx:zohocrm.contact.otherCity}</homeCity>
                                                                    <homeState>{$ctx:zohocrm.contact.otherState}</homeState>
                                                                    <homeCountry>{$ctx:zohocrm.contact.otherCountry}</homeCountry>
                                                                    <homePostalCode>{$ctx:zohocrm.contact.otherZip}</homePostalCode>
                                                                    <unsubscribed>false</unsubscribed>
                                                                    <fax>{$ctx:zohocrm.account.fax}</fax>
                                                                </pipelinedeals.createPerson>
                                                                <sequence key="removeResponseHeaders" />
																
                                                                <property name="zohocrm.potential.personId" expression="json-eval($.id)" />
																
                                                                <!-- START: Proceed to update the custom field only if the contact has been created successfully. -->
                                                                <filter source="boolean(get-property('zohocrm.potential.personId'))" regex="true">
                                                                    <then>
                                                                        <property name="id" expression="fn:concat('zohocrm_contactId:', get-property('zohocrm.potential.contactId'), ',pipelinedeals_personId:', get-property('zohocrm.potential.personId'))" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createPerson" />
                                                                            <with-param name="id" value="{$ctx:id}" />
                                                                            <with-param name="status" value="Success" />
                                                                            <with-param name="message" value="Person has been created successfully." />
                                                                        </call-template>
                                                                        <!--Update the PipelineDeals person ID in the zohoCrm account in the custom field 'PipelineDeals Person ID' -->
                                                                        <script language="js">
																			<![CDATA[
																				//constructing the xml data in order to update the contact in ZohoCrm								
																				var personId = mc.getProperty('zohocrm.potential.personId');								
																				var xmlData="<Contacts> <row no=\"1\"> <FL val=\"PipelineDeals Person ID\">" + personId + "</FL> </row> </Contacts>";															
																				mc.setProperty('zohocrm.xmlData', xmlData);
																			]]>
																		</script>
																		
                                                                        <!-- Update the ZohoCRM contact with PipelineDeals Person ID. -->
                                                                        <zohocrm.init>
                                                                            <scope>crmapi</scope>
                                                                            <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                                                                            <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                                                                        </zohocrm.init>
                                                                        <zohocrm.updateRecords>
                                                                            <moduleType>Contacts</moduleType>
                                                                            <id>{$ctx:zohocrm.potential.contactId}</id>
                                                                            <xmlData>{$ctx:zohocrm.xmlData}</xmlData>
                                                                        </zohocrm.updateRecords>
                                                                        <sequence key="removeResponseHeaders" />
																		
                                                                        <property name="zohocrm.contactId" expression="//content[../val/text() = 'Id']" />
                                                                        
																		<!-- Append an error message to the user only if the update fails. -->
                                                                        <filter source="boolean(get-property('zohocrm.contactId'))" regex="false">
                                                                            <then>
                                                                                <property name="id" expression="fn:concat('zohocrm_contactId:', get-property('zohocrm.potential.contactId'), ',pipelinedeals_companyId:', get-property('zohocrm.potential.personId'))" />
                                                                                <property name="message" expression="json-eval($)" />
                                                                                <call-template target="responseHandlerTemplate">
                                                                                    <with-param name="activity" value="zohocrm_updateContact" />
                                                                                    <with-param name="id" value="{$ctx:id}" />
                                                                                    <with-param name="status" value="Error" />
                                                                                    <with-param name="message" value="{$ctx:message}" />
                                                                                </call-template>
                                                                            </then>
                                                                        </filter>
                                                                    </then>
                                                                    <else>
                                                                        <property name="message" expression="json-eval($)" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createCompany" />
                                                                            <with-param name="id" value="{$ctx:id.empty}" />
                                                                            <with-param name="status" value="Error" />
                                                                            <with-param name="message" value="{$ctx:message}" />
                                                                        </call-template>
                                                                    </else>
                                                                </filter>
                                                                <!-- END: Proceed to update the custom field only if the contact has been created successfully. -->
                                                            </then>
                                                        </filter>
                                                        <!-- END: Proceed to create the person in Pipeline Deals (for the ZohoCRM contact) if not already created. -->
														
                                                        <!-- START: Proceed to create the deal only if company and contact exists in PipelineDeals. -->
                                                        <filter xpath="boolean(get-property('zohocrm.potential.companyId')) and boolean(get-property('zohocrm.potential.personId'))">
                                                            <then>
                                                                <property name="deal.customFields" expression="fn:concat('{&quot;', get-property('pipelinedeals.zohocrmPotentialCustomFieldId'), '&quot; : &quot;#', get-property('zohocrm.potential.potentialId'), '&quot;}')" />
                                                                
																<!-- Create a deal based on the ZohoCRM potential. -->
                                                                <property name="messageType" value="application/json" scope="axis2" />
																
                                                                <pipelinedeals.init>
                                                                    <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                                                                    <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                                                                    <attributes>id</attributes>
                                                                </pipelinedeals.init>
                                                                <pipelinedeals.createDeal>
                                                                    <name>{$ctx:zohocrm.potential.name}</name>
                                                                    <summary>{$ctx:zohocrm.potential.description}</summary>
                                                                    <status>2</status>
                                                                    <customFields>{$ctx:deal.customFields}</customFields>
                                                                    <expectedCloseDate>{$ctx:zohocrm.potential.expectedCloseDate}</expectedCloseDate>
                                                                    <isArchived>false</isArchived>
                                                                    <value>{$ctx:zohocrm.potential.amount}</value>
                                                                    <primaryContactId>{$ctx:zohocrm.potential.personId}</primaryContactId>
                                                                    <companyId>{$ctx:zohocrm.potential.companyId}</companyId>
                                                                    <probability>{$ctx:zohocrm.potential.probability}</probability>
                                                                    <dealStageId>{$ctx:pipelinedeals.followupStageId}</dealStageId>
                                                                    <sourceId>{$ctx:pipelinedeals.zohocrmDealSourceId}</sourceId>
                                                                </pipelinedeals.createDeal>
                                                                <sequence key="removeResponseHeaders" />
																
                                                                <property name="pipelinedeals.dealId" expression="json-eval($.id)" />
                                                                
																<!-- START: Proceed to update the custom field only if the deal has been created successfully. -->
                                                                <filter source="boolean(get-property('pipelinedeals.dealId'))" regex="true">
                                                                    <then>
                                                                        <property name="id" expression="fn:concat('zohocrm_potentialId:', get-property('zohocrm.potential.potentialId'), ',pipelinedeals_dealId:', get-property('pipelinedeals.dealId'))" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createDeal" />
                                                                            <with-param name="id" value="{$ctx:id}" />
                                                                            <with-param name="status" value="Success" />
                                                                            <with-param name="message" value="Deal has been created successfully." />
                                                                        </call-template>
                                                                        
																		<!--Update the PipelineDeals deal ID in the zohoCrm account in the custom field 'PipelineDeals Deal ID' -->
                                                                        <script language="js">
																			<![CDATA[
																				//constructing the xml data in order to update the account in ZohoCrm								
																				var dealId = mc.getProperty('pipelinedeals.dealId');								
																				var xmlData="<Potentials> <row no=\"1\"> <FL val=\"PipelineDeals Deal ID\">" + dealId + "</FL> <FL val=\"Stage\">Archive</FL> </row> </Potentials>";															
																				mc.setProperty('zohocrm.xmlData', xmlData);
																			]]>
																		</script>
																		
																		<!-- Update the ZohoCRM potential with PipelineDeals Deal ID. -->
                                                                        <zohocrm.init>
                                                                            <scope>crmapi</scope>
                                                                            <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                                                                            <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                                                                        </zohocrm.init>
                                                                        <zohocrm.updateRecords>
                                                                            <moduleType>Potentials</moduleType>
                                                                            <id>{$ctx:zohocrm.potential.potentialId}</id>
                                                                            <xmlData>{$ctx:zohocrm.xmlData}</xmlData>
                                                                        </zohocrm.updateRecords>
                                                                        <sequence key="removeResponseHeaders" />
																		
                                                                        <property name="zohocrm.potentialId" expression="//content[../val/text() = 'Id']" />
                                                                        <!-- Append an error message to the user only if the update fails. -->
                                                                        <filter source="boolean(get-property('zohocrm.potentialId'))" regex="false">
                                                                            <then>
                                                                                <property name="id" expression="fn:concat('zohocrm_potentialId:', get-property('zohocrm.potential.potentialId'), ',pipelinedeals_dealId:', get-property('pipelinedeals.dealId'))" />
                                                                                <property name="message" expression="json-eval($)" />
                                                                                <call-template target="responseHandlerTemplate">
                                                                                    <with-param name="activity" value="zohocrm_updatePotential" />
                                                                                    <with-param name="id" value="{$ctx:id}" />
                                                                                    <with-param name="status" value="Error" />
                                                                                    <with-param name="message" value="{$ctx:message}" />
                                                                                </call-template>
                                                                            </then>
                                                                        </filter>
                                                                    </then>
                                                                    <else>
                                                                        <property name="message" expression="json-eval($)" />
                                                                        <call-template target="responseHandlerTemplate">
                                                                            <with-param name="activity" value="pipelinedeals_createDeal" />
                                                                            <with-param name="id" value="{$ctx:id.empty}" />
                                                                            <with-param name="status" value="Error" />
                                                                            <with-param name="message" value="{$ctx:message}" />
                                                                        </call-template>
                                                                    </else>
                                                                </filter>
                                                                <!-- START: Proceed to update the custom field only if the company has been created successfully. -->
                                                            </then>
                                                            <else>
                                                                <property name="id" expression="fn:concat('zohocrm_potentialId:', get-property('zohocrm.potential.potentialId'))" />
                                                                <call-template target="responseHandlerTemplate">
                                                                    <with-param name="activity" value="pipelinedeals_createDeal" />
                                                                    <with-param name="id" value="{$ctx:id}" />
                                                                    <with-param name="status" value="Error" />
                                                                    <with-param name="message" value="Deal was not created since the associated company and/or contact could not be created." />
                                                                </call-template>
                                                            </else>
                                                        </filter>
                                                        <!-- END: Proceed to create the deal only if company and contact exists in PipelineDeals. -->
                                                    </then>
                                                </filter>
                                                <!-- END: Proceed only if the potential is in 'Follow-Up' stage. -->
                                            </then>
                                        </filter>
                                        <!-- END: Proceed to create the deal only if it is not created already. -->
										
                                        <!--Increment the potentialIndex count -->
                                        <property name="zohoCrm.potentialIndex" expression="get-property('operation', 'zohoCrm.potentialIndex') + 1" scope="operation" />
                                        
										<!-- START: Loopback if all the iterations are done. -->
										<filter xpath="get-property('zohoCrm.potentialCount') = get-property('operation', 'zohoCrm.potentialIndex')">
                                            <then>
												<!-- Append a message to send to the user if no deals were created. -->
                                                <filter source="get-property('operation','dealsInFollowUp')" regex="0.0">
                                                    <then>
                                                        <call-template target="responseHandlerTemplate">
                                                            <with-param name="activity" value="pipelinedeals_createDeal" />
                                                            <with-param name="id" value="{$ctx:id.empty}" />
                                                            <with-param name="status" value="Skipped" />
                                                            <with-param name="message" value="There are no new potentials in the 'Follow-Up stage'." />
                                                        </call-template>
                                                    </then>
                                                </filter>
                                                <loopback />
                                            </then>
                                        </filter>
										<!-- START: Loopback if all the iterations are done. -->
                                    </sequence>
                                </target>
                            </iterate>
                            <!-- END: FOR EACH potential -->
                        </else>
                    </filter>
                    <!-- END: Proceed only if there any potentials created/modified on the current day of execution. -->
                </else>
            </filter>
            <!-- END: Error case: If the response is having errors then display the error message given by the API. -->
        </inSequence>
        <outSequence>
            <!-- Send the constructed response to the user. -->
            <payloadFactory media-type="json">
                <format>
					{
					   "Response":{
						   "process":"pipelinedeals_retrievePotentialsAndCreateDeals",
						   "activityResponse": [$1]
					   }
					}
			   </format>
                <args>
                    <arg expression="get-property('operation', 'responseString')" />
                </args>
            </payloadFactory>
            <send />
        </outSequence>
    </target>
</proxy>
Sample Request for retrieving potentials in the 'follow-up' stage from Zoho CRM and creating them as deals in PipelindeDeals (only the potentials which are created/modified on the current day)
{
	"zohocrm":{
		"accessToken":"aa979d7d069c362c5f2525f89ca0f31"
	},
	"pipelinedeals":{
		"apiUrl": "https://api.pipelinedeals.com",
    		"apiKey": "TNHIHSDN0ZDFFFieJ2"
	}
}

Note

All parameters are self-explanatory and specific to the individual APIs. 

Execution time of the scenario would be fairly longer since a timeout has been added in the scenario to prevent duplication of companies and people in PipelineDeals.

Retrieving people and adding them to the subscribers' list 

  1. Retrieve people from the PipelineDeals API using the listPeople operation.
  2. Retrieve the subscribers' list which matches the provided list name using the listSubscriberLists operation in the MailChimp API.
  3. Add them to the default subscribers list in the MailChimp API for future campaign purposes using the addSubscribersToList operation.
PipelineDeals operations
MailChimp operations
Samples
Sample Proxy for retrieving people from PipelineDeals and adding them to the MailChimp subscribers' list (identified the list name)
<?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.
-->
<!-- The proxy will retrieve people from PipelineDeals on a daily basis and add them to the subscribers' list in MailChimp. -->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="pipelinedeals_addPeopleToSubscribersList" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <!-- ZohoCrm Properties -->
            <property name="mailchimp.apiUrl" expression="json-eval($.mailchimp.apiUrl)" />
            <property name="mailchimp.apiKey" expression="json-eval($.mailchimp.apiKey)" />
            <property name="mailchimp.listName" expression="json-eval($.mailchimp.listName)" />
			
            <!-- PipelineDeals Properties -->
            <property name="pipelinedeals.apiUrl" value="https://api.pipelinedeals.com" />
            <property name="pipelinedeals.apiKey" expression="json-eval($.pipelinedeals.apiKey)" />
            <property name="pipelinedeals.modifiedAfter" expression="json-eval($.pipelinedeals.modifiedAfter)" />
			
            <!-- Common properties -->
            <property name="id.empty" value="{}" />
            <property name="responseString" value="" scope="operation" />
            <property name="activityName" value="pipelinedeals_addPeopleToSubscribersList" scope="operation" />
			
            <!-- If the user has not provided the modifiedAfter date, only the users modifed on the current day of execution will be considered. -->
            <script language="js">
				<![CDATA[
					var modifiedAfter = mc.getProperty('pipelinedeals.modifiedAfter');				
					if(modifiedAfter == null || modifiedAfter == ''){
						var fromDate = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
						mc.setProperty('pipelinedeals.modifiedAfter', encodeURIComponent(fromDate));
					}
				]]>
			</script>
			
            <!-- List all the people who were modified after the 'modifiedAfter'. -->
            <pipelinedeals.init>
                <apiUrl>{$ctx:pipelinedeals.apiUrl}</apiUrl>
                <apiKey>{$ctx:pipelinedeals.apiKey}</apiKey>
                <attributes>email</attributes>
            </pipelinedeals.init>
            <pipelinedeals.listPeople>
                <personModifiedFromDate>{$ctx:pipelinedeals.modifiedAfter}</personModifiedFromDate>
                <perPage>200</perPage>
            </pipelinedeals.listPeople>
            <sequence key="removeResponseHeaders" />
			
            <property name="pipelinedeals.people" expression="json-eval($.entries)" />
			
			<!--The script mediator will construct the array of subscribers to update. -->
            <script language="js">
				<![CDATA[
					// Construct the email array to add to the subscribers' list in Mailchimp.
					var people = eval("(" + mc.getProperty('pipelinedeals.people') + ")");
					var batchEmailString = '';		
					var noOfPeople = people.length;
					if(noOfPeople > 0){
						for(var i=0; i<noOfPeople; i++){
							var email = people[i].email;
							if(email != null && email != ''){
								batchEmailString += '{ "email": { "email": "' + email + '" }, "email_type": "text" }';
							}
							if(i < noOfPeople-1){
								batchEmailString += ',';
							}
						}
						batchEmailString = '[' + batchEmailString + ']';
					}
					mc.setProperty('mailchimp.batchEmailString', batchEmailString);
				]]>
			</script>
			
            <!-- Terminate the scenario if there are no new people in 'PipelineDeals' to add to the subscribers' list. -->
            <filter source="boolean(get-property('mailchimp.batchEmailString'))" regex="false">
                <then>
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="mailchimp_addPeopleToSubscribersList" />
                        <with-param name="id" value="{$ctx:id.empty}" />
                        <with-param name="status" value="Error" />
                        <with-param name="message" value="There are no new people in 'PipelineDeals' to add to the subscribers' list." />
                    </call-template>
                    <loopback />
                </then>
            </filter>
			
            <!-- List the subscribers' list which match the provided list name -->
            <mailchimp.init>
                <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                <format>json</format>
            </mailchimp.init>
            <mailchimp.listSubscriberLists>
                <listName>{$ctx:mailchimp.listName}</listName>
                <sortField>created</sortField>
                <sortDirection>DESC</sortDirection>
            </mailchimp.listSubscriberLists>
            <sequence key="removeResponseHeaders" />
			
            <property name="mailchimp.listCount" expression="count(//data)" />
			
            <!-- START: Proceed only if at least one list is returned. -->
            <filter source="get-property('mailchimp.listCount')" regex="0.0">
                <then>
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="mailchimp_getSubscribersList" />
                        <with-param name="id" value="{$ctx:id.empty}" />
                        <with-param name="status" value="Skipped" />
                        <with-param name="message" value="There are no subscribers' list that match the name." />
                    </call-template>
                </then>
                <else>
                    <property name="mailchimp.listId" expression="//data[1]/id/text()" />
					
                    <!-- Subscribe people to list -->
                    <mailchimp.init>
                        <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
                        <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
                        <format>json</format>
                    </mailchimp.init>
                    <mailchimp.addSubscribersToList>
                        <listId>{$ctx:mailchimp.listId}</listId>
                        <batch>{$ctx:mailchimp.batchEmailString}</batch>
                        <doubleOptin>false</doubleOptin>
                        <updateExisting>true</updateExisting>
                    </mailchimp.addSubscribersToList>
                    <sequence key="removeResponseHeaders" />
					
                    <property name="mailchimp.addCount" expression="json-eval($.add_count)" />
                    <property name="id" expression="fn:concat('mailchimp_subscribersListId:', get-property('mailchimp.listId'))" />
                    <filter xpath="get-property('mailchimp.addCount') &gt; 0">
                        <then>
                            <property name="status" value="Success" />
                            <property name="message" expression="fn:concat(get-property('mailchimp.addCount'), ' subscriber(s) have been added to the list.')" />
                        </then>
                        <else>
                            <property name="status" value="Skipped" />
                            <property name="message" value="All people are already part of the subscribers' list." />
                        </else>
                    </filter>
                    <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="mailchimp_addPeopleToSubscribersList" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="{$ctx:status}" />
                        <with-param name="message" value="{$ctx:message}" />
                    </call-template>
                    <property name="mailchimp.errorCount" expression="json-eval($.error_count)" />
					
                    <filter xpath="get-property('mailchimp.errorCount') &gt; 0">
                        <then>
                            <property name="message" expression="json-eval($.errors)" />
                            <call-template target="responseHandlerTemplate">
                                <with-param name="activity" value="mailchimp_addPeopleToSubscribersList" />
                                <with-param name="id" value="{$ctx:id}" />
                                <with-param name="status" value="Skipped" />
                                <with-param name="message" value="{$ctx:message}" />
                            </call-template>
                        </then>
                    </filter>
                </else>
            </filter>
            <!-- END: Proceed only if at least one list is returned. -->
            <loopback />
        </inSequence>
        <outSequence>
            <!-- Send the constructed response to the user. -->
            <payloadFactory media-type="json">
                <format>
					{
					   "Response":{
						   "process":"pipelinedeals_addPeopleToSubscribersList",
						   "activityResponse": [$1]
					   }
					}
			    </format>
                <args>
                    <arg expression="get-property('operation', 'responseString')" />
                </args>
            </payloadFactory>
            <send />
        </outSequence>
    </target>
</proxy>
Sample Request for retrieving people from PipelineDeals and adding them to the MailChimp subscribers' list (identified the list name)
{
	"mailchimp":{
		"apiUrl": "https://us9.api.mailchimp.com",
    		"apiKey": "444e6b63ca5c81d2143a161226043b-us9",
    		"listName": "Pipelinedeals Deal Subscribers"
	},
	"pipelinedeals":{
		"apiKey": "TNHIHSDN0ZFFieJ2"
	}
}

Note

 The following are the parameter descriptions:

  • mailchimp.listName : The name of the list to which subscribers would be added (results would be unpredictable if the invalid list name is provided).