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

Contact Management in Printavo

The second use case in the Printavo business scenario is contact management. This page describes the relevant tasks and the operations you use in the Printavo connector and the other ESB connectors. It contains the following sections:

Overview

The flow for contact management is illustrated in the following diagram. The ESB connectors for Sendloop  and Base CRM will be used to connect to each service.

Retrieving clickers of the campaign and creating the clickers as leads

  1. Retrieve the details of the campaign from the Sendloop API using the getEmailCampaign operation.
  2. Retrieve details of the clickers from the Sendloop API using the getCampaignLinkClickers operation.
  3. Retrieve the subscriber lists available from the Sendloop API using the listSubscriberLists operation.
  4. if there is no list existing for the campaign, create a new list in the Sendloop API using the createSubscriberList operation.
  5. Retrieve all the subscribers for the existing list using the listSubscribers operation in the Sendloop API.
  6. Add the subscriber to the new list using the subscribe operation in the Sendloop API.
  7. Create these clickers as leads in the Base CRM API using the createLead operation. 
Sendloop operations
Base CRM operations
Samples
Sample Proxy for retrieving clickers of the campaign in Sendloop and adding them to a new list, creating a new list for each campaign if it is not already created and creating those clickers as leads in Base CRM
<?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 clickers for a given campaign and add them to a new list and create them as leads in basecrm-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="printavo_retrieveClickersAndCreateLeads" transports="https" startOnLoad="true" trace="disable">
   <description />
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- Sendloop Properties-->
         <property name="sendloop.apiUrl" expression="json-eval($.sendloop.apiUrl)" />
         <property name="sendloop.apiKey" expression="json-eval($.sendloop.apiKey)" />
         <property name="sendloop.campaignId" expression="json-eval($.sendloop.campaignId)" />
         
		 <!-- BaseCRM Properties-->
         <property name="uri.var.basecrm.apiKey" expression="json-eval($.basecrm.apiKey)" />
         <property name="uri.var.basecrm.apiUrl" value="https://api.getbase.com" />
         <property name="basecrm.leadUrl" value="https://leads.futuresimple.com" />
         <property name="basecrm.version1Url" value="https://sales.futuresimple.com" />
         <property name="basecrm.email" expression="json-eval($.basecrm.email)" />
         <property name="basecrm.password" expression="json-eval($.basecrm.password)" />
        
		<!--Call sendloop connector getEmailCampaign method to retrieve details of clickers-->
         <sendloop.init>
            <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
            <apiKey>{$ctx:sendloop.apiKey}</apiKey>
            <format>json</format>
         </sendloop.init>
         <sendloop.getEmailCampaign>
            <campaignId>{$ctx:sendloop.campaignId}</campaignId>
         </sendloop.getEmailCampaign>
         
		 <property name="sendloop.campaignlistId" expression="json-eval($.Campaign.Lists[0])" />
         <property name="sendloop.campaignName" expression="json-eval($.Campaign.CampaignName)" />
         
		 <sequence key="removeResponseHeaders" />
		 <!-- START: Proceed only if there is a campaign from the given ID. -->
         <filter source="boolean(get-property('sendloop.campaignName'))" regex="false">
            <then>
               <property name="id" expression="fn:concat('sendloop_campaignId:',get-property('sendloop.campaignId'))" />
               <property name="status" value="Error" />
               <property name="message" expression="json-eval($)" />
               <!--Call the responseHandler template-->
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="sendloop_getCampaign" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
            <else>
               <!--Call sendloop connector getCampaignLinkClickers method to retrieve details of clickers-->
               <sendloop.init>
                  <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
                  <apiKey>{$ctx:sendloop.apiKey}</apiKey>
                  <format>json</format>
               </sendloop.init>
               <sendloop.getCampaignLinkClickers>
                  <campaignId>{$ctx:sendloop.campaignId}</campaignId>
               </sendloop.getCampaignLinkClickers>
               
			   <sequence key="removeResponseHeaders" />
               
			  <!-- START: Proceed only if the clickers are retrieved successfully. -->
               <filter source="$axis2:HTTP_SC" regex="200">
                  <then>
                     <property name="sendloop.clickersCount" expression="count(//Data)" scope="operation" />
                     <property name="clickerIndex" expression="0" scope="operation" />
					 <property name="sendloop.clickerResponse" expression="0" scope="operation" />
					 <property name="sendloop.leadResponse" expression="0" scope="operation" />
                     
					 <!-- START: Proceed only if there are one or more clickers. -->
					 <filter xpath="get-property('operation', 'sendloop.clickersCount') = 0">
                        <then>
                           <property name="id" value="{}" />
                           <property name="status" value="Skipped" />
                           <property name="message" value="No clickers for the campaign." />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="id" value="{$ctx:id}" />
                              <with-param name="activity" value="printavo_retrieveClickers" />
                              <with-param name="status" value="{$ctx:status}" />
                              <with-param name="message" value="{$ctx:message}" />
                           </call-template>
                           <loopback />
                        </then>
                        <else>
						  <property name="sendloop.clickers" expression="json-eval($.Data)" />
                          <!--Call sendloop connector listSubscriberLists method to retrieve the subscriber lists available-->
						  <sendloop.init>
                              <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
                              <apiKey>{$ctx:sendloop.apiKey}</apiKey>
                              <format>json</format>
                           </sendloop.init>
                           <sendloop.listSubscriberLists />
						   
                           <property name="sendloop.subscriberLists" expression="json-eval($.Lists)" />
						   
						   <!--To check whether there is a list already for the given campaign-->
                           <script language="js">
							  <![CDATA[
								 var listArray = eval("(" + mc.getProperty('sendloop.subscriberLists') + ")");
								 var campaignName = ''+mc.getProperty('sendloop.campaignName');
								 var listId;
								 
								 for(var i=0 ; i<listArray.length ;i++) {
								   var listName = listArray[i].Name;
								   if(listName== campaignName) {
										listId = listArray[i].ListID;
										mc.setProperty("sendloop.newListId",listId);
										break;
								   }
								 }
							  ]]>
							 </script>
						
						   <!-- START: Proceed only if there is no list existing for the campaign. -->
                           <filter source="boolean(get-property('sendloop.newListId'))" regex="false">
                              <then>
                                 <sendloop.init>
                                    <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
                                    <apiKey>{$ctx:sendloop.apiKey}</apiKey>
                                    <format>json</format>
                                 </sendloop.init>
                                 <sendloop.createSubscriberList>
                                    <listName>{$ctx:sendloop.campaignName}</listName>
                                    <optInMode>Single</optInMode>
                                 </sendloop.createSubscriberList>
                                 <sequence key="removeResponseHeaders" />
                                 <property name="sendloop.newListId" expression="json-eval($.ListID)" />
								 
								 <!-- START: Check whether the subscriber is added to the new list. -->
								 <filter source="boolean(get-property('sendloop.newListId'))" regex="false">
								   <then>
									  <property name="id" value="{}" />
									  <property name="status" value="Error" />
									  <property name="message" expression="json-eval($.)" />
								   </then>
								   <else>
									  <property name="id" expression="fn:concat('sendloop_listId:',get-property('sendloop.newListId'))"/>
									  <property name="status" value="Success" />
									  <property name="message" value="A new list has been successfully created for the clickers." />
								   </else>
								 </filter>
								 <!-- END: Check whether the subscriber is added to the new list. -->
								 <call-template target="responseHandlerTemplate">
								   <with-param name="activity" value="sendloop_createSubscriberList" />
								   <with-param name="id" value="{$ctx:id}" />
								   <with-param name="status" value="{$ctx:status}" />
								   <with-param name="message" value="{$ctx:message}" />
								 </call-template>
								 
                              </then>
                           </filter>
						    <!-- END: Proceed only if there is no list existing for the campaign. -->
						   
                           <payloadFactory media-type="json">
                              <format>{
								 "data": $1
							  }</format>
                              <args>
                                 <arg expression="get-property('sendloop.clickers')" />
                              </args>
                           </payloadFactory>
                           
						   <!--BEGIN : FOR EACH clicker-->
                           <iterate continueParent="false" id="clickerIterator" expression="//data" sequential="true">
                              <target>
                                 <sequence>
                                    <property name="sendloop.subscriberId" expression="json-eval($.data.SubscriberID)" />
                                    
									<!--Call Sendloop connector listSubscribers method to retrieve all the subscribers for the existing list -->
                                    <sendloop.init>
                                       <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
                                       <apiKey>{$ctx:sendloop.apiKey}</apiKey>
                                       <format>json</format>
                                    </sendloop.init>
                                    <sendloop.listSubscribers>
                                       <listId>{$ctx:sendloop.campaignlistId}</listId>
                                    </sendloop.listSubscribers>
                                    <property name="sendloop.subscribers" expression="json-eval($.Subscribers)" />
                                    
									<!--Retrieve all the information related to the clicker(Subscriber)-->
									<script language="js">
										<![CDATA[
											 var subscriberArray = eval("(" + mc.getProperty('sendloop.subscribers') + ")");
											 var subscirberId = ''+mc.getProperty('sendloop.subscriberId');
											 var subscriberEmail;
											 
											 for(var i=0 ; i<subscriberArray.length ;i++) {
											   var id = subscriberArray[i].SubscriberID;
											   if(id== subscirberId) {
													var subscriberObj = subscriberArray[i];
													subscriberEmail = subscriberArray[i].EmailAddress;
													
													for (var key in subscriberObj) {
														if(new java.lang.String(key).startsWith('CustomField')) {
															var name = subscriberObj[key];
															var firstName = name.split(' ')[0];
															var lastName = name.split(' ')[1];
															
															mc.setProperty("sendloop.subscriberFirstName",firstName);
															mc.setProperty("sendloop.subscriberLastName",lastName);
															break;
														}
													}
													mc.setProperty("sendloop.subscriberEmail",subscriberEmail);
											   }
											 }
									    ]]>
									</script>
                                    
								
									<!-- Calling basecrm-createLeadsSeq sequence to create leads in basecrm for the clickers-->
									<sequence key="basecrm-createLeadsSeq" />
                                    
									<!-- START: Check whether the subscriber list is already there. -->
									<filter source="boolean(get-property('sendloop.newListId'))" regex="true">
										<then>
											<!--Call Sendloop connector subscribe method to add the subscriber to the new list -->
											<sendloop.init>
											   <apiUrl>{$ctx:sendloop.apiUrl}</apiUrl>
											   <apiKey>{$ctx:sendloop.apiKey}</apiKey>
											   <format>json</format>
											</sendloop.init>
											<sendloop.subscribe>
											   <emailAddress>{$ctx:sendloop.subscriberEmail}</emailAddress>
											   <subscriberListId>{$ctx:sendloop.newListId}</subscriberListId>
											</sendloop.subscribe>
											<property name="sendloop.subscribe" expression="json-eval($.Success)" />
											
											<!-- START: Creating list call is successfull. -->
											<filter source="$axis2:HTTP_SC" regex="200">
												<then>
													<!-- START: Check whether the subscriber is added to the new list. -->
													<filter xpath="(get-property('sendloop.subscribe'))='true'">
													   <then>
														  <property name="sendloop.clickerResponse" expression="get-property('operation','sendloop.clickerResponse') + 1" scope="operation" />
														  <property name="id" expression="fn:concat('sendloop_subscriberId:',get-property('sendloop.subscriberId'),',sendloop_listId:',get-property('sendloop.newListId'))" />
														  <property name="status" value="Success" />
														  <property name="message" value="The subscriber has been successfully added to the created list." />
														  <call-template target="responseHandlerTemplate">
															<with-param name="activity" value="sendloop_addSubscriber" />
															<with-param name="id" value="{$ctx:id}" />
															<with-param name="status" value="{$ctx:status}" />
															<with-param name="message" value="{$ctx:message}" />
														  </call-template>
													   </then>
													</filter>
													<!-- END: Check whether the subscriber is added to the new list. -->
												</then>
												<else>
													<property name="id" expression="fn:concat('sendloop_subscriberId:',get-property('sendloop.subscriberId'),',sendloop_listId:',get-property('sendloop.newListId'))" />
													<property name="status" value="Error" />
													<property name="message" expression="json-eval($.)" />
													<call-template target="responseHandlerTemplate">
													   <with-param name="activity" value="sendloop_addSubscriber" />
													   <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: Creating list call is successfull. -->
										</then>
									</filter>
									<!-- END: Check whether the subscriber list is already there. -->
                                    <property name="clickerIndex" expression="get-property('operation','clickerIndex') + 1" scope="operation" />
                                    
                                    <filter xpath="get-property('operation','clickerIndex') = get-property('operation', 'sendloop.clickersCount')">
                                       <then>
											<!-- START: Check if no clickers are proceeding. -->
											<filter xpath="(get-property('operation','sendloop.leadResponse') = '0.0') and (get-property('operation','sendloop.clickerResponse') = '0.0')">
												<then>
													<property name="id" value="{}" />
													<property name="status" value="Skipped" />
													<property name="message" value="All the clickers have been added to the new list in Sendloop and as well as created as leads in BaseCRM" />
													<call-template target="responseHandlerTemplate">
													   <with-param name="activity" value="printavo_retrieveClickersAndCreateLeads" />
													   <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>
													<!-- START: Check if no clickers are proceeding as leads in BaseCRM. -->
													<filter xpath="(get-property('operation','sendloop.leadResponse') = '0.0')">
														<then>
															<property name="id" value="{}" />
															<property name="status" value="Skipped" />
															<property name="message" value="All the clickers have been successfully created as leads in BaseCRM" />
															<call-template target="responseHandlerTemplate">
															   <with-param name="activity" value="basecrm_createLeads" />
															   <with-param name="id" value="{$ctx:id}" />
															   <with-param name="status" value="{$ctx:status}" />
															   <with-param name="message" value="{$ctx:message}" />
															</call-template>
														</then>
													</filter>
													<!-- END: Check if no clickers are proceeding as leads in BaseCRM. -->
													
													<!-- START: Check if no clickers are proceeding as susbcribers to the new list. -->
													<filter xpath="(get-property('operation','sendloop.clickerResponse') = '0.0')">
														<then>
															<property name="id" value="{}" />
															<property name="status" value="Skipped" />
															<property name="message" value="All the clickers have been successfully added to the new list in the sendloop" />
															<call-template target="responseHandlerTemplate">
															   <with-param name="activity" value="sendloop_addSubscriber" />
															   <with-param name="id" value="{$ctx:id}" />
															   <with-param name="status" value="{$ctx:status}" />
															   <with-param name="message" value="{$ctx:message}" />
															</call-template>
														</then>
													</filter>
													<!-- END: Check if no clickers are proceeding as susbcribers to the new list. -->
												</else>
											</filter>
											<!-- END: Check if no clickers are proceeding. -->
                                          <loopback />
                                       </then>
                                    </filter>
                                 </sequence>
                              </target>
                           </iterate>
                           <!--=END : FOR EACH clicker-->
                        </else>
                     </filter>
					 <!-- END: Proceed only if there are one or more clickers. -->
                  </then>
                  <else>
                     <property name="id" value="{}" />
                     <property name="status" value="Error" />
                     <property name="message" expression="json-eval($.)" />
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="sendloop_retrieveCampaignClickers" />
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="status" value="{$ctx:status}" />
                        <with-param name="message" value="{$ctx:message}" />
                     </call-template>
                     <loopback />
                  </else>
               </filter>
			    <!-- END: Proceed only if the clickers are retrieved successfully. -->
            </else>
         </filter>
         <!-- END: Proceed only if there is a campaign from the given ID. -->
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>{
				"Response":{
					"process":"printavo_retrieveClickersAndCreateLeads",
					"activityResponse":[$1]
				}
				}</format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
</proxy>       
Sample Request for retrieving clickers of the campaign in Sendloop and adding them to a new list, creating a new list for each campaign if it is not already created and creating those clickers as leads in Base CRM
{
	"sendloop":{
		"apiUrl": "https://y9913dd-7dd6e1.sendloop.com",
    	"apiKey": "62ea-b11c-d076-2310-4295-e5db-8928-a3db",
		"campaignId": "8"
	},
	"basecrm":{
		"apiKey": "67cdbde3a294d8cc87e308a896056271c2da225e1b10f06d2a6d551af22a6fb6",
		"email":"yasasi.gama@gmail.com",
		"password":"yasasi123"
	}
}       

Note

 The following are the parameter descriptions:

  • sendloop.campaignId: The ID of the campaign in Sendloop to which the clickers will be retrieved.

Retrieving won deals and creating draft quotes

  1. Converting a lead to a contact in the Base CRM API is an offline process.
  2. Creating and converting a deal to 'Won' in the Base CRM API is an offline process.
  3. Retrieve the details of the contact from the Base CRM API using the getContactById operation. 
  4. Create customers in the Printavo API using the createCustomer operation if it does not exist in the Printavo API.
  5. Create a quote for the won deals in the Printavo API using the createOrder operation.
Base CRM operations
Printavo operations
Samples
Sample Proxy for retrieving won deals in Base CRM and creating draft quotes for them in Printavo. A new customer will be created if the customer related to the deal is not already existing in Printavo
<?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 contacts and quotes respectively in Printavo for the won deals in BaseCRM-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="printavo_retrieveWonDealsAndCreateQuotes" transports="https" startOnLoad="true" trace="disable">
   <description />
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- BaseCRM Properties-->
         <property name="uri.var.basecrm.apiKey" expression="json-eval($.basecrm.apiKey)" />
         <property name="uri.var.basecrm.apiUrl" value="https://api.getbase.com" />
         <property name="basecrm.dealUrl" value="https://leads.futuresimple.com" />
         <property name="basecrm.version1Url" value="https://sales.futuresimple.com" />
         <property name="basecrm.email" expression="json-eval($.basecrm.email)" />
         <property name="basecrm.password" expression="json-eval($.basecrm.password)" />
         <property name="uri.var.basecrm.wonStageId" expression="json-eval($.basecrm.wonStageId)" />
         
		 <!-- Printavo Properties-->
         <property name="printavo.apiUrl" value="https://www.printavo.com" />
         <property name="printavo.apiKey" expression="json-eval($.printavo.apiKey)" />
         
		 <!--Call BaseCRM api method to list deals in won stage-->
		 <!--The method listDeals implemented in BaseCRM connector does not have any filter parameters-->
         <property name="uri.var.apikey" expression="fn:concat('Bearer ',get-property('uri.var.basecrm.apiKey'))" />
         <header name="Accept" value="application/json" scope="transport" />
         <header name="Authorization" expression="get-property('uri.var.apikey')" scope="transport" />
         <call>
            <endpoint>
               <http method="get" uri-template="{uri.var.basecrm.apiUrl}/v2/deals?stage_id={uri.var.basecrm.wonStageId}" />
            </endpoint>
         </call>
         
		 <!-- START: Proceed only if the deals are retrieved successfully. -->
		 <filter source="$axis2:HTTP_SC" regex="200">
			<then>
				 <property name="basecrm.dealCount" expression="count(//items)" scope="operation" />
				 <property name="dealIndex" value="0" scope="operation" />
				 <sequence key="removeResponseHeaders" />
				
				 <!-- START: Proceed only if there is atleast one deal. -->
				 <filter xpath="(get-property('basecrm.dealCount'))='0.0'">
					<then>
					   <property name="id" value="{}" />
					   <property name="status" value="Skipped" />
					   <property name="message" value="No won deals to process." />
					   <call-template target="responseHandlerTemplate">
						  <with-param name="id" value="{$ctx:id}" />
						  <with-param name="activity" value="basecrm_retrieveWonDeals" />
						  <with-param name="status" value="{$ctx:status}" />
						  <with-param name="message" value="{$ctx:message}" />
					   </call-template>
					   <loopback />
					</then>
					<else>
					   <!--BEGIN : FOR EACH deal-->
					   <iterate continueParent="false" id="dealIterator" expression="//items" sequential="true">
						  <target>
							 <sequence>
								<property name="uri.var.basecrm.dealId" expression="json-eval($.items.data.id)" />
								<property name="basecrm.dealPrintavoQuotes" expression="json-eval($.items.data.custom_fields.printavo_quote)" />
								<!-- START: Process only if the quote creation in printavo is required. -->
								<filter source="boolean(get-property('basecrm.dealPrintavoQuotes'))" regex="true">
								   <then>
									  <property name="id" expression="fn:concat('basecrm_dealId:',get-property('uri.var.basecrm.dealId'))" />
									  <property name="status" value="Skipped" />
									  <property name="message" value="A quote has been already created for the deal" />
									  <call-template target="responseHandlerTemplate">
										 <with-param name="id" value="{$ctx:id}" />
										 <with-param name="activity" value="printavo_createQuote" />
										 <with-param name="status" value="{$ctx:status}" />
										 <with-param name="message" value="{$ctx:message}" />
									  </call-template>
								   </then>
								   <else>
									  <property name="printavo.quoteDueDate" expression="json-eval($.items.data.estimated_close_date)" />
									  <property name="printavo.quoteValue" expression="json-eval($.items.data.value)" />
									  <property name="printavo.quoteNote" expression="fn:concat('deal_value:',get-property('printavo.quoteValue'))" />
									  <property name="basecrm.contactId" expression="json-eval($.items.data.contact_id)" />
									  
									  <!--Construct the date in the format which printavo orders accept-->
									  <script language="js">
										<![CDATA[
											var dueDate = ''+mc.getProperty('printavo.quoteDueDate');
											var year = dueDate.split('-')[0];
											var month = dueDate.split('-')[1];
											var date = dueDate.split('-')[2];  
											 
											var dateString = month+'/'+date+'/'+year;
											mc.setProperty("printavo.quoteDueDate",dateString);
										]]>
									  </script>
									  
									  <!--Call basecrm connector getContactById method to get the details of the contact -->
									  <basecrm.init>
										 <email>{$ctx:basecrm.email}</email>
										 <responseType>json</responseType>
										 <apiUrl>{$ctx:basecrm.version1Url}</apiUrl>
										 <password>{$ctx:basecrm.password}</password>
									  </basecrm.init>
									  <basecrm.getContactById>
										 <contactId>{$ctx:basecrm.contactId}</contactId>
									  </basecrm.getContactById>
									  <property name="uri.var.basecrm.contactId" expression="json-eval($.contact.id)" />
						
									  <!-- START: Process only if the contact is retrieved successfully. -->
									  <filter source="boolean(get-property('uri.var.basecrm.contactId'))" regex="false">
										 <then>
											<property name="id" expression="fn:concat('basecrm_dealId:',get-property('uri.var.basecrm.dealId'))" />
											<property name="status" value="Error" />
											<property name="message" expression="json-eval($.)" />
											<call-template target="responseHandlerTemplate">
											   <with-param name="activity" value="basecrm_getContactDetails" />
											   <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="basecrm.printavoCustomer" expression="json-eval($.contact.custom_fields.printavo_customer.value)" />
											<property name="printavo.customerEmail" expression="json-eval($.contact.email)" />
											<property name="printavo.customerFirstName" expression="json-eval($.contact.first_name)" />
											<property name="printavo.customerLastName" expression="json-eval($.contact.last_name)" />
											<property name="printavo.customerCompany" expression="json-eval($.contact.organisation_name)" />
											<property name="printavo.customerPhone" expression="json-eval($.contact.phone)" />
											<property name="printavo.customerFax" expression="json-eval($.contact.fax)" />
										
											<!-- START: Process only if the contact creation in printavo is required. -->
											<filter source="boolean(get-property('basecrm.printavoCustomer'))" regex="false">
											   <then>
												  
												  <!--Call printavo connector createCustomer method to create a customer-->
												  <printavo.init>
													 <apiUrl>{$ctx:printavo.apiUrl}</apiUrl>
													 <apiKey>{$ctx:printavo.apiKey}</apiKey>
												  </printavo.init>
												  <printavo.createCustomer>
													 <firstName>{$ctx:printavo.customerFirstName}</firstName>
													 <lastName>{$ctx:printavo.customerLastName}</lastName>
													 <fax>{$ctx:printavo.customerFax}</fax>
													 <company>{$ctx:printavo.customerCompany}</company>
													 <email>{$ctx:printavo.customerEmail}</email>
													 <phone>{$ctx:printavo.customerPhone}</phone>
												  </printavo.createCustomer>
												  <property name="basecrm.printavoCustomer" expression="json-eval($.id)" />
												  
												  <!-- START: Process only if the customer creation is successfull -->
												  <filter source="boolean(get-property('basecrm.printavoCustomer'))" regex="false">
													 <then>
														<property name="id" expression="fn:concat('basecrm_contactId:',get-property('uri.var.basecrm.contactId'))" />
														<property name="status" value="Error" />
														<property name="message" expression="json-eval($.)" />
														<call-template target="responseHandlerTemplate">
														   <with-param name="activity" value="printavo_createCustomers" />
														   <with-param name="id" value="{$ctx:id}" />
														   <with-param name="status" value="{$ctx:status}" />
														   <with-param name="message" value="{$ctx:message}" />
														</call-template>
														<loopback />
													 </then>
													 <else>
														<payloadFactory media-type="json">
														   <format>{
																	"data": {
																		"custom_fields": {
																		  "printavo_customer": "$1"
																		}
																	}
																}</format>
														   <args>
															  <arg expression="get-property('basecrm.printavoCustomer')" />
														   </args>
														</payloadFactory>
													   
													    <!---Call basecrm api method to update the contact-->
													    <header name="Accept" value="application/json" scope="transport" />
														<header name="Authorization" expression="get-property('uri.var.apikey')" scope="transport" />
														<call>
														   <endpoint>
															  <http method="put" uri-template="{uri.var.basecrm.apiUrl}/v2/contacts/{uri.var.basecrm.contactId}" />
														   </endpoint>
														</call>
														
														<property name="basecrm.updatedContactId" expression="json-eval($.data.id)" />
														
														<!-- START: Process only if contact updation is failed in basecrm -->
														<filter source="boolean(get-property('basecrm.updatedContactId'))" regex="false">
														   <then>
															  <property name="id" value="{}" />
															  <property name="status" value="Error" />
															  <property name="message" expression="json-eval($.)" />
															  <call-template target="responseHandlerTemplate">
																 <with-param name="activity" value="baseCrm_updateContact" />
																 <with-param name="id" value="{$ctx:id}" />
																 <with-param name="status" value="{$ctx:status}" />
																 <with-param name="message" value="{$ctx:message}" />
															  </call-template>
														   </then>
														</filter>
														<!-- END: Process only if contact updation is failed in basecrm -->
													 </else>
												  </filter>
												  <!-- END: Process only if the customer creation is successful -->
											   </then>
											</filter>
											<!-- END: Process only if the contact creation in printavo is required. -->
											
											<!-- START: Process only if the printavo customer has been already created for the basecrm contact. -->
											<filter source="boolean(get-property('basecrm.printavoCustomer'))" regex="true">
											   <then>
												  
												  <!-- Calling printavo-getUserIdSeq sequence to get the user ID-->
												  <sequence key="printavo-getUserIdSeq" />
												  
												  <!-- Calling printavo-getOrderIdSeq sequence to get the order status ID-->
												  <sequence key="printavo-getOrderIdSeq" />
												  
												  <!--Call printavo connector createOrder method to create a quote for the won deal-->
												  <printavo.init>
													 <apiUrl>{$ctx:printavo.apiUrl}</apiUrl>
													 <apiKey>{$ctx:printavo.apiKey}</apiKey>
												  </printavo.init>
												  <printavo.createOrder>
													 <userId>{$ctx:printavo.userId}</userId>
													 <orderstatusId>{$ctx:printavo.OrderStatusId}</orderstatusId>
													 <customerId>{$ctx:basecrm.printavoCustomer}</customerId>
													 <formattedDueDate>{$ctx:printavo.quoteDueDate}</formattedDueDate>
													 <notes>{$ctx:printavo.quoteNote}</notes>
												  </printavo.createOrder>
												  <property name="printavo.orderId" expression="json-eval($.id)" />
												  
												  <!-- START: Process only if the order has been created successfully -->
												  <filter source="boolean(get-property('printavo.orderId'))" regex="false">
													 <then>
														<property name="id" expression="fn:concat('basecrm_dealId:',get-property('uri.var.basecrm.dealId'))" />
														<property name="status" value="Error" />
														<property name="message" expression="json-eval($.)" />
														<call-template target="responseHandlerTemplate">
														   <with-param name="activity" value="printavo_createQuote" />
														   <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('printavo_quoteId:',get-property('printavo.orderId'),',basecrm_dealId:',get-property('uri.var.basecrm.dealId'))" />
														<property name="status" value="Success" />
														<property name="message" value="The quote has been successfully created for the won deal." />
														<call-template target="responseHandlerTemplate">
														   <with-param name="activity" value="printavo_createQuote" />
														   <with-param name="id" value="{$ctx:id}" />
														   <with-param name="status" value="{$ctx:status}" />
														   <with-param name="message" value="{$ctx:message}" />
														</call-template>
														
														<payloadFactory media-type="json">
														   <format>{
																	"data": {
																		"custom_fields": {
																		  "printavo_quote": "$1"
																		}
																	}
																}</format>
														   <args>
															  <arg expression="get-property('printavo.orderId')" />
														   </args>
														</payloadFactory>
														
														<!--Call basecrm api method to update the deal with the created quote ID-->
														<header name="Accept" value="application/json" scope="transport" />
														<header name="Authorization" expression="get-property('uri.var.apikey')" scope="transport" />
														<call>
														   <endpoint>
															  <http method="put" uri-template="{uri.var.basecrm.apiUrl}/v2/deals/{uri.var.basecrm.dealId}" />
														   </endpoint>
														</call>
														<property name="basecrm.updatedDealId" expression="json-eval($.data.id)" />
														
														 <!-- START: Process only if the updation has not been successful -->
														<filter source="boolean(get-property('basecrm.updatedDealId'))" regex="false">
														   <then>
															  <property name="id" value="{}" />
															  <property name="status" value="Error" />
															  <property name="message" expression="json-eval($.)" />
															  <call-template target="responseHandlerTemplate">
																 <with-param name="activity" value="baseCrm_updateDeal" />
																 <with-param name="id" value="{$ctx:id}" />
																 <with-param name="status" value="{$ctx:status}" />
																 <with-param name="message" value="{$ctx:message}" />
															  </call-template>
														   </then>
														</filter>
														<!-- END: Process only if the updation has not been successful -->
													 </else>
												  </filter>
												  <!-- END: Process only if the printavo customer has been already created for the basecrm contact. -->
											   </then>
											</filter>
											<!-- END: Process only if the printavo customer has been already created for the basecrm contact. -->
										 </else>
									  </filter>
									  <!-- END: Process only if the contact is retrieved successfully. -->
								   </else>
								</filter>
								<!-- END: Process only if the quote creation in printavo is required. -->
								<property name="dealIndex" expression="get-property('operation','dealIndex') + 1" scope="operation" />
								<filter xpath="get-property('operation','dealIndex') = get-property('operation', 'basecrm.dealCount')">
								   <then>
									  <loopback />
								   </then>
								</filter>
							 </sequence>
						  </target>
					   </iterate>
					   <!--END : FOR EACH deal-->
					</else>
				 </filter>
				 <!-- END: Proceed only if there is atleast one deal. -->
			</then>
			<else>
			   <property name="id" value="{}" />
               <property name="status" value="Error" />
               <property name="message" expression="json-eval($.)" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="basecrm_retrieveDeals" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback/>
			</else>
		 </filter>
		 <!-- END: Proceed only if the deals are retrieved successfully. -->
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>{
				"Response":{
					"process":"printavo_retrieveWonDealsAndCreateQuotes",
					"activityResponse":[$1]
				}
				}</format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
</proxy>
Sample Request for retrieving won deals in Base CRM and creating draft quotes for them in Printavo. A new customer will be created if the customer related to the deal is not already existing in Printavo
{
	"basecrm":{
		"apiKey": "67cdbde3a294d8cc87e308a896056271c2da225e1b10f06d2a6d551af22a6fb6",
		"email":"yasasi.gama@gmail.com",
		"password":"yasasi123",
		"wonStageId":"4473804"
	},
	"printavo":{
		"apiKey":"be69aef93636a049afa4f5676ebe1ab5"
	}
}

Note

 The following are the parameter descriptions:

  • basecrm.wonStageId: The ID of the 'won' stage of the deals in Base CRM.