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

Managing Orders in Zoho CRM

The third use case in the  Zoho CRM business scenario is managing orders. This page describes the related tasks and the operations you use in the Zoho CRM connector and the other ESB connectors. 

Overview

The flow for managing orders is illustrated in the following diagram. The ESB connectors for Zoho CRM and QuickBooks will be used to connect to each service.

Prerequisites
  • There must be at least one vendor and one item created in QuickBooks.
  • All the QuickBooks items in productItemMap must have the ExpenseAccountRef field.

  1. Retrieve vendors from QuickBooks using the query operation, and then create vendors in Zoho CRM using insertRecords.
  2. Retrieve items from QuickBooks using the   query operation, and then create products in Zoho CRM using the  insertRecords operation.
  3. Create purchase orders for the vendors and products in Zoho CRM using insertRecords, and then create them in QuickBooks using createPurchaseOrder. Use the getRecordsById operation to retrieve the details of the purchase orders. You can associate these purchase orders with relevant contacts in Zoho CRM. 
Zoho CRM operations
QuickBooks operations

Samples

The "qbQueryCondition":"MetaData.CreateTime" property in the request will determine the date from which the vendors and items will be fetched.

Sample Template for Creating and Retrieving Purchase Orders
<!-- This template creates a purchase order in Zoho CRM and then retrieves the purchase order details -->
<template name="zohocrm-createAndRetrievePurchaseOrder" xmlns="http://ws.apache.org/ns/synapse">
	<!-- Zoho CRM parameters -->
	<property name="zohoApiUrl" description="The Zoho api URL" />
	<property name="zohoAccessToken" description="Encrypted alphanumeric string to authenticate the Zoho credentials" />
	<property name="zohoScope" description="Zoho CRM scope, Specify the value as crmapi" />
	<property name="zohoNewFormat" description="The newFormat, an integer determine weather null valus should be excluded(1) or included(2)" />
	<property name="zohoVersion" description="Coloumns selected" />
	<property name="zohoXmlData" description="The xml string containing the data of the purchase order to be inserted" />
	<property name="zohoWfTrigger" description="The wfTrigger parameter is used to trigger the workflow rule while inserting record into CRM account" />	
	<property name="zohoDuplicateCheck" description="The wfTrigger parameter is used to trigger the workflow rule while inserting record into CRM account" />			   
	<sequence>
		<!-- zoho CRM properties -->
		<property name="uri.var.zohoApiUrl" expression="json-eval($.zohoApiUrl)"/>
		<property name="uri.var.zohoAccessToken" expression="json-eval($.zohoAccessToken)"/>
		<property name="uri.var.zohoScope" expression="json-eval($.zohoScope)"/>
		<property name="uri.var.zohoNewFormat" expression="json-eval($.zohoNewFormat)"/>
		<property name="uri.var.zohoVersion" expression="json-eval($.zohoVersion)"/>
		<property name="uri.var.zohoXmlData" expression="json-eval($.zohoXmlData)"/>
		<property name="uri.var.zohoWfTrigger" expression="json-eval($.zohoWfTrigger)"/>
		<property name="uri.var.zohoDuplicateCheck" expression="json-eval($.zohoDuplicateCheck)"/>
		<!-- isApproval property was set to false so the case will immediately add to the account and can proceed with other API calls,
		 otherwise manual approving should be needed-->
		<property name="uri.var.zohoIsApproval" value="false"/>
		<property name="uri.var.zohoModuleType" value="PurchaseOrders"/>		
	  <!-- zoho CRM insert Purchse Order -->
      <zohocrm.init>
		  <apiUrl>{$ctx:uri.var.zohoApiUrl}</apiUrl>
		  <accessToken>{$ctx:uri.var.zohoAccessToken}</accessToken>
		  <scope>{$ctx:uri.var.zohoScope}</scope>
      </zohocrm.init>	  
      <zohocrm.insertRecords>
		<newFormat>{$ctx:uri.var.zohoNewFormat}</newFormat>
        <version>{$ctx:uri.var.zohoVersion}</version>
        <xmlData>{$ctx:uri.var.zohoXmlData}</xmlData>
        <wfTrigger>{$ctx:uri.var.zohoWfTrigger}</wfTrigger>
		<duplicateCheck>{$ctx:uri.var.zohoDuplicateCheck}</duplicateCheck>
		<isApproval>{$ctx:uri.var.zohoIsApproval}</isApproval>
		<moduleType>{$ctx:uri.var.zohoModuleType}</moduleType>
      </zohocrm.insertRecords>
		<call-template target="responseHandlerTemplate">
			<!-- parameter values will be passed on to a sequence template -->
			(
			<with-param name="activityName" value="zohoCRM_insertPurchaseOrder" />
			|
			) *
		</call-template>		
		<!-- Retrieving created Purchse Order ID --> 
		<property name="uri.var.purchaseOrderId" expression="json-eval($.response.result.recorddetail.FL[0].content)"/>		
		<!-- Check the availability of Purchase Order ID to  proceed with other API calls -->		
		<filter source="boolean(get-property('uri.var.purchaseOrderId'))" regex="false">
			<loopback/>
		</filter>	
		<header name="Expires" scope="transport" action="remove" />
		<header name="Content-Type" scope="transport" action="remove" />
		<header name="Date" scope="transport" action="remove" />
		<header name="Server" scope="transport" action="remove" />
		<header name="Transfer-Encoding" scope="transport" action="remove" />
		<header name="Connection" scope="transport" action="remove" />
		<header name="Vary" scope="transport" action="remove" />
		<header name="Content-Encoding" scope="transport" action="remove" />
	  <!-- zoho CRM retrieve created Purchse Order-->
      <zohocrm.init>
		  <apiUrl>{$ctx:uri.var.zohoApiUrl}</apiUrl>
		  <accessToken>{$ctx:uri.var.zohoAccessToken}</accessToken>
		  <scope>{$ctx:uri.var.zohoScope}</scope>
      </zohocrm.init>	  
      <zohocrm.getRecordsById>
        <id>{$ctx:uri.var.purchaseOrderId}</id>
	    <newFormat>{$ctx:uri.var.zohoNewFormat}</newFormat>
        <version>{$ctx:uri.var.zohoVersion}</version>
		<moduleType>{$ctx:uri.var.zohoModuleType}</moduleType>
      </zohocrm.getRecordsById>		
	  <call-template target="responseHandlerTemplate">
		  <!-- parameter values will be passed on to a sequence template -->
		  (
		  <with-param name="activityName" value="zohoCRM_getPurchaseOrderById" />|
		  ) *
	  </call-template>	
	<!-- Retrieving Purchse Order details --> 
	<property name="uri.var.purchaseOrderDetails" expression="json-eval($.response.result.PurchaseOrders.row.FL[0].content)"/>  
	<!-- Check the availability of purchaseOrderDetails to proceed with other API calls -->		
	<filter source="boolean(get-property('uri.var.purchaseOrderDetails'))" regex="false">
		<loopback/>
	</filter>	
	</sequence>
</template>
Sample Proxy for Creating ZohoCRM Vendors Using the QuickBooks Vendors
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="zohocrm_createVendorsFromQb"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">	  
	  <!-- ZohoCRM insertRecords parameters -->
	  <property name="zohoApiUrl" expression="json-eval($.zohoApiUrl)"/>
      <property name="zohoAccessToken" expression="json-eval($.zohoAccessToken)"/>
      <property name="zohoScope" expression="json-eval($.zohoScope)"/>
      <property name="zohoNewFormat" expression="json-eval($.zohoNewFormat)"/>
      <property name="zohoVersion" expression="json-eval($.zohoVersion)"/>
      <property name="zohoWfTrigger" expression="json-eval($.zohoWfTrigger)"/>
      <property name="zohoDuplicateCheck" expression="json-eval($.zohoDuplicateCheck)"/>
      <property name="zohoIsApproval" expression="json-eval($.zohoIsApproval)"/>
	  <property name="zohoVendorModuleType" value="Vendors"/>	  
	  <!-- QuickBooks createQuote parameters-->
	 <property name="qbConsumerKey" expression="json-eval($.qbConsumerKey)"/>
	 <property name="qbAccessToken" expression="json-eval($.qbAccessToken)"/>
	 <property name="qbAccessTokenSecret" expression="json-eval($.qbAccessTokenSecret)"/>
	 <property name="qbResponseType" expression="json-eval($.qbResponseType)"/>
	 <property name="qbApiUrl" expression="json-eval($.qbApiUrl)"/>
	 <property name="qbCompanyId" expression="json-eval($.qbCompanyId)"/>
	 <property name="qbConsumerSecret" expression="json-eval($.qbConsumerSecret)"/>
	 <property name="qbQueryCondition" expression="json-eval($.qbQueryCondition)"/>
	 <property name="qbQueryString" expression="fn:concat('select * from vendor where ', get-property('qbQueryCondition'))" />		 
	 <quickbooks.init>
		<consumerKey>{$ctx:qbConsumerKey}</consumerKey>
		<accessToken>{$ctx:qbAccessToken}</accessToken>
		<accessTokenSecret>{$ctx:qbAccessTokenSecret}</accessTokenSecret>
		<responseType>{$ctx:qbResponseType}</responseType>
		<apiUrl>{$ctx:qbApiUrl}</apiUrl>
		<companyId>{$ctx:qbCompanyId}</companyId>
		<consumerSecret>{$ctx:qbConsumerSecret}</consumerSecret>
	 </quickbooks.init>	 
	 <quickbooks.query>
		<queryString>{$ctx:qbQueryString}</queryString>
	 </quickbooks.query>	 
	<property name="vendorList" expression="json-eval($.QueryResponse.Vendor)"/>
	<call-template target="responseHandlerTemplate">
		<!-- parameter values will be passed on to a sequence template -->
		(
		<with-param name="activityName" value="quickbooks_queryVendors" />
		|
		) *
	</call-template>	
	<filter source="boolean(get-property('vendorList'))" regex="false">
		<then>
			<loopback/>
		</then>
	</filter>		
	<script language="js">
         <![CDATA[
		     var vendorList = mc.getProperty("vendorList");		 
			 var jsn = eval("(" + vendorList + ")");
			 var vendorDisplayName='';
			 var xmlData='';			 
            if (typeof(jsn) == "object" && (jsn.join == undefined)) {
				// vendor list is an object
				 vendorDisplayName = jsn.DisplayName;				
				 xmlData += '<row no="1"><FL val="Vendor Name">' + vendorDisplayName + '</FL></row>';
		    }else{
			     // vendor list is an array
				 for (var i = 0; i < jsn.length ; i++) {
				 vendorDisplayName = jsn[i].DisplayName;				 
				 xmlData += '<row no="' + eval((i+1)) + '"><FL val="Vendor Name">' + vendorDisplayName + '</FL></row>';
			 }
			}
			xmlData = '<Vendors>' + xmlData + '</Vendors>';
			mc.setProperty('vendorXmlData', xmlData);
		 ]]>
	</script>		 
      <zohocrm.init>
        <scope>{$ctx:zohoScope}</scope>
        <accessToken>{$ctx:zohoAccessToken}</accessToken>
        <apiUrl>{$ctx:zohoApiUrl}</apiUrl>
      </zohocrm.init>	  
      <zohocrm.insertRecords>
	    <moduleType>{$ctx:zohoVendorModuleType}</moduleType>
        <duplicateCheck>{$ctx:zohoDuplicateCheck}</duplicateCheck>
        <xmlData>{$ctx:vendorXmlData}</xmlData>
        <isApproval>{$ctx:zohoIsApproval}</isApproval>
        <wfTrigger>{$ctx:zohoWfTrigger}</wfTrigger>
        <newFormat>{$ctx:zohoNewFormat}</newFormat>
        <version>{$ctx:zohoVersion}</version>
      </zohocrm.insertRecords> 	  
	<call-template target="responseHandlerTemplate">
		<!-- parameter values will be passed on to a sequence template -->
		(
		<with-param name="activityName" value="zohocrm_insertRecords" />
		|
		) *
	</call-template> 	  
      <loopback/>
      </inSequence>
      <outSequence>
			<property name="messageType" value="application/json" scope="axis2"></property>
			<payloadFactory media-type="json">
				<format>
					{
					"Response":[$1]
					}
				</format>
				<args>
					<arg expression="get-property('uri.var.responseString')" />
				</args>
			</payloadFactory>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>                                                                                          


Sample Request for Creating ZohoCRM Vendors Using the QuickBooks Vendors
{
	"zohoApiUrl":"https://crm.zoho.com",
	"zohoAccessToken":"64c4b7358cf641a9321fc898bfe1d8fe",
	"zohoScope":"crmapi",
	"qbConsumerKey":"qyprdKKN9W7FNe546oJCRri7IMcDhq",
	"qbConsumerSecret":"EDCf6KvJg7Ofova5ovAthlr4lw2jyj1N0bvNU43j",
	"qbAccessToken":"qyprddkWFHEbRCPQYZfK3HptJHUGdGdHu7lC2VNdtLq2q12z",
	"qbAccessTokenSecret":"xI161dzkp88YaaBfkPD2yASuQvYzP1RzqbgQA5dR",
	"qbResponseType":"application/json",
	"qbCompanyId":"1242238695",
	"qbQueryCondition":"MetaData.CreateTime > '2009-10-14T04:05:05-07:00'"
}
Sample Proxy for Creating ZohoCRM Products Using the QuickBooks Items
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="zohocrm_createProductsFromQb"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">	  
	  <!-- ZohoCRM insertRecords parameters -->
	  <property name="zohoApiUrl" expression="json-eval($.zohoApiUrl)"/>
      <property name="zohoAccessToken" expression="json-eval($.zohoAccessToken)"/>
      <property name="zohoScope" expression="json-eval($.zohoScope)"/>
      <property name="zohoNewFormat" expression="json-eval($.zohoNewFormat)"/>
      <property name="zohoVersion" expression="json-eval($.zohoVersion)"/>
      <property name="zohoWfTrigger" expression="json-eval($.zohoWfTrigger)"/>
      <property name="zohoDuplicateCheck" expression="json-eval($.zohoDuplicateCheck)"/>
      <property name="zohoIsApproval" expression="json-eval($.zohoIsApproval)"/>
	  <property name="zohoProductModuleType" value="Products"/>	  
	  <!-- QuickBooks createQuote parameters-->
	 <property name="qbConsumerKey" expression="json-eval($.qbConsumerKey)"/>
	 <property name="qbAccessToken" expression="json-eval($.qbAccessToken)"/>
	 <property name="qbAccessTokenSecret" expression="json-eval($.qbAccessTokenSecret)"/>
	 <property name="qbResponseType" expression="json-eval($.qbResponseType)"/>
	 <property name="qbApiUrl" expression="json-eval($.qbApiUrl)"/>
	 <property name="qbCompanyId" expression="json-eval($.qbCompanyId)"/>
	 <property name="qbConsumerSecret" expression="json-eval($.qbConsumerSecret)"/>
	 <property name="qbQueryCondition" expression="json-eval($.qbQueryCondition)"/>
	 <property name="qbQueryString" expression="fn:concat('select * from item where ', get-property('qbQueryCondition'))" /> 
	 <quickbooks.init>
		<consumerKey>{$ctx:qbConsumerKey}</consumerKey>
		<accessToken>{$ctx:qbAccessToken}</accessToken>
		<accessTokenSecret>{$ctx:qbAccessTokenSecret}</accessTokenSecret>
		<responseType>{$ctx:qbResponseType}</responseType>
		<apiUrl>{$ctx:qbApiUrl}</apiUrl>
		<companyId>{$ctx:qbCompanyId}</companyId>
		<consumerSecret>{$ctx:qbConsumerSecret}</consumerSecret>
	 </quickbooks.init>	 
	 <quickbooks.query>
		<queryString>{$ctx:qbQueryString}</queryString>
	 </quickbooks.query>	 
	<property name="itemList" expression="json-eval($.QueryResponse.Item)"/>	 	
	<call-template target="responseHandlerTemplate">
		<!-- parameter values will be passed on to a sequence template -->
		(
		<with-param name="activityName" value="quickbooks_queryItems" />
		|
		) *
	</call-template>	
	<filter source="boolean(get-property('itemList'))" regex="false">
		<then>
			<loopback/>
		</then>
	</filter>		
	<script language="js">
         <![CDATA[
		     var itemList = mc.getProperty("itemList");		 
			 var jsn = eval("(" + itemList + ")");
			 var itemName='';
			 var itemUnitPrice='';
			 var itemDescription='';
			 var xmlData='';			 
            if (typeof(jsn) == "object" && (jsn.join == undefined)) {
				// item list is an object
				 itemName = jsn.Name;
				if(jsn.UnitPrice != undefined && jsn.UnitPrice != null){
				 itemUnitPrice = jsn.UnitPrice;
				}
				if(jsn.Description != undefined && jsn.Description != null){
				 itemDescription = jsn.Description;
				}				
				 xmlData += '<row no="1"><FL val="Product Name">' + itemName + '</FL><FL val="Description">' + itemDescription + '</FL><FL val="Unit Price">' + itemUnitPrice +'</FL></row>';
		    }else{
			     // item list is an array
				 for (var i = 0; i < jsn.length ; i++) {
				 itemName = jsn[i].Name;
				if(jsn[i].UnitPrice != undefined && jsn[i].UnitPrice != null){
				 itemUnitPrice = jsn[i].UnitPrice;
				}				 
				if(jsn[i].Description != undefined && jsn[i].Description != null){
				 itemDescription = jsn[i].Description;
				}				 
				 xmlData += '<row no="' + eval((i+1)) + '"><FL val="Product Name">' + itemName + '</FL><FL val="Description">' + itemDescription + '</FL><FL val="Unit Price">' + itemUnitPrice +'</FL></row>';
			 }
			}
			xmlData = '<Products>' + xmlData + '</Products>';
			mc.setProperty('productXmlData', xmlData);
		 ]]>
	</script>	  
      <zohocrm.init>
        <scope>{$ctx:zohoScope}</scope>
        <accessToken>{$ctx:zohoAccessToken}</accessToken>
        <apiUrl>{$ctx:zohoApiUrl}</apiUrl>
      </zohocrm.init>	  
      <zohocrm.insertRecords>
	    <moduleType>{$ctx:zohoProductModuleType}</moduleType>
        <duplicateCheck>{$ctx:zohoDuplicateCheck}</duplicateCheck>
        <xmlData>{$ctx:productXmlData}</xmlData>
        <isApproval>{$ctx:zohoIsApproval}</isApproval>
        <wfTrigger>{$ctx:zohoWfTrigger}</wfTrigger>
        <newFormat>{$ctx:zohoNewFormat}</newFormat>
        <version>{$ctx:zohoVersion}</version>
      </zohocrm.insertRecords> 	  
	<call-template target="responseHandlerTemplate">
		<!-- parameter values will be passed on to a sequence template -->
		(
		<with-param name="activityName" value="zohocrm_insertRecords" />
		|
		) *
	</call-template>  
      <loopback/>
      </inSequence>
      <outSequence>
			<property name="messageType" value="application/json" scope="axis2"></property>
			<payloadFactory media-type="json">
				<format>
					{
					"Response":[$1]
					}
				</format>
				<args>
					<arg expression="get-property('uri.var.responseString')" />
				</args>
			</payloadFactory>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>                                                                                                            
Sample Request for Creating ZohoCRM Products Using the QuickBooks Items
 {
	"zohoApiUrl":"https://crm.zoho.com",
	"zohoAccessToken":"038d4a2d22bd8bb80ea8a3438b9e7bab",
	"zohoScope":"crmapi",
	"qbConsumerKey":"qyprdKKN9W7FNe546oJCRri7IMcDhq",
	"qbConsumerSecret":"EDCf6KvJg7Ofova5ovAthlr4lw2jyj1N0bvNU43j",
	"qbAccessToken":"qyprddkWFHEbRCPQYZfK3HptJHUGdGdHu7lC2VNdtLq2q12z",
	"qbAccessTokenSecret":"xI161dzkp88YaaBfkPD2yASuQvYzP1RzqbgQA5dR",
	"qbResponseType":"application/json",
	"qbCompanyId":"1242238695",
	"qbQueryCondition":"MetaData.CreateTime > '2009-10-14T04:05:05-07:00'"
}


Sample Proxy for Creating Purchase Orders in ZohoCRM and QuickBooks
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="zohocrm_quickbooks_createPurchaseOrder"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>		
		<!-- Zoho CRM API call related properties -->
		<property name="zohoApiUrl" expression="json-eval($.zohoApiUrl)"/>
		<property name="zohoAccessToken" expression="json-eval($.zohoAccessToken)"/>
		<property name="zohoScope" expression="json-eval($.zohoScope)"/>
		<property name="zohoNewFormat" expression="json-eval($.zohoNewFormat)"/>
		<property name="zohoVersion" expression="json-eval($.zohoVersion)"/>
		<property name="zohoXmlData" expression="json-eval($.zohoXmlData)"/>
		<property name="zohoWfTrigger" expression="json-eval($.zohoWfTrigger)"/>
		<property name="zohoDuplicateCheck" expression="json-eval($.zohoDuplicateCheck)"/>		
		<!-- Quickbooks API call related properties -->
         <property name="qbConsumerKey" expression="json-eval($.qbConsumerKey)"/>
         <property name="qbAccessToken" expression="json-eval($.qbAccessToken)"/>
         <property name="qbAccessTokenSecret" expression="json-eval($.qbAccessTokenSecret)"/>
         <property name="qbResponseType" expression="json-eval($.qbResponseType)"/>
         <property name="qbApiUrl" expression="json-eval($.qbApiUrl)"/>
         <property name="qbCompanyId" expression="json-eval($.qbCompanyId)"/>
         <property name="qbConsumerSecret" expression="json-eval($.qbConsumerSecret)"/>		 
		 <property name="qbCustomField" expression="json-eval($.qbCustomField)"/>
         <property name="qbAttachableRef" expression="json-eval($.qbAttachableRef)"/>
         <property name="qbDocNumber" expression="json-eval($.qbDocNumber)"/>
         <property name="qbTxnDate" expression="json-eval($.qbTxnDate)"/>
         <property name="qbPrivateNote" expression="json-eval($.qbPrivateNote)"/>
         <property name="qbLinkedTxn" expression="json-eval($.qbLinkedTxn)"/>
         <property name="qbVendorRef" expression="json-eval($.qbVendorRef)"/>
         <property name="qbAPAccountRef" expression="json-eval($.qbAPAccountRef)"/>
         <property name="qbTotalAmt" expression="json-eval($.qbTotalAmt)"/>
         <property name="qbClassRef" expression="json-eval($.qbClassRef)"/>
         <property name="qbSalesTermRef" expression="json-eval($.qbSalesTermRef)"/>
         <property name="qbDueDate" expression="json-eval($.qbDueDate)"/>
         <property name="qbVendorAddr" expression="json-eval($.qbVendorAddr)"/>
         <property name="qbShipAddr" expression="json-eval($.qbShipAddr)"/>
         <property name="qbShipMethodRef" expression="json-eval($.qbShipMethodRef)"/>
         <property name="qbPurchaseOrderStatus" expression="json-eval($.qbPurchaseOrderStatus)"/>
         <property name="qbTxnTaxDetail" expression="json-eval($.qbTxnTaxDetail)"/>
         <property name="qbTaxCodeRef" expression="json-eval($.qbTaxCodeRef)"/>
         <property name="qbCurrencyRef" expression="json-eval($.qbCurrencyRef)"/>
         <property name="qbExchangeRate" expression="json-eval($.qbExchangeRate)"/>
         <property name="qbGlobalTaxCalculation" expression="json-eval($.qbGlobalTaxCalculation)"/>
		 <property name="productItemMap" expression="json-eval($.productItemMap)"/>		 
		<call-template target="zohocrm-createAndRetrievePurchaseOrder">
		   <!-- parameter values will be passed on to a sequence template -->
		   (
		   <with-param name="zohoApiUrl" value="{$ctx:zohoApiUrl}" /> |		   
		   <with-param name="zohoAccessToken" value="{$ctx:zohoAccessToken}" /> |
		   <with-param name="zohoScope" value="{$ctx:zohoScope}" /> |		   
		   <with-param name="zohoNewFormat" value="{$ctx:zohoNewFormat}" /> |
		   <with-param name="zohoVersion" value="{$ctx:zohoVersion}" /> |
		   <with-param name="zohoXmlData" value="{$ctx:zohoXmlData}" /> |		   
		   <with-param name="zohoWfTrigger" value="{$ctx:zohoWfTrigger}" /> |
		   <with-param name="zohoDuplicateCheck" value="{$ctx:zohoDuplicateCheck}" /> |	
		   ) *
		</call-template>
	 <property name="purchaseOrderAttributes" expression="json-eval($.response.result.PurchaseOrders.row.FL)"/>	 
	 <!-- Following script will create the Line Object using the zoho crm purchase order details, to be sent to quickbooks for purchase order creation -->
     <script language="js">
			var jsn = eval("(" + mc.getProperty("purchaseOrderAttributes") + ")");
			var products;
			var productAttributes;
			var lineObject;
			var productName;
			var listPrice;
			var quantity;
			var productId;
			var itemBasedExpenseLineDetail;			
			var lineArray = eval("([])");
			var productItemMap = eval("("+mc.getProperty('productItemMap')+")");
			
			for (var i = 0; i &lt; jsn.length ; i++) {
				if(jsn[i].val == "Product Details"){
					products = jsn[i].product;
				}
			}			
		if (typeof(products) == "object" &amp;&amp; (products.join == undefined)) { // Products is a JSON object, not an array
			productAttributes = products.FL;
			lineObject=eval("({})");			
			for (var i = 0; i &lt; productAttributes.length ; i++) { 	
				if(productAttributes[i].val == "Product Name"){
					productName = productAttributes[i].content;
				}				
				if(productAttributes[i].val == "List Price"){
					listPrice = productAttributes[i].content;
				}
				if(productAttributes[i].val == "Quantity"){
					quantity = productAttributes[i].content;
				}
				if(productAttributes[i].val == "Product Id"){
					productId = productAttributes[i].content;
				}				
			}																								
				lineObject.Id = "1";
				lineObject.DetailType = "ItemBasedExpenseLineDetail";
				itemBasedExpenseLineDetail = eval("({})");
				itemBasedExpenseLineDetail.UnitPrice = eval(listPrice);
				itemBasedExpenseLineDetail.Qty = eval(quantity);
				itemBasedExpenseLineDetail.ItemRef = eval("({})");
				itemBasedExpenseLineDetail.ItemRef.name = productName;
				itemBasedExpenseLineDetail.ItemRef.value = productItemMap[productId];
				lineObject.ItemBasedExpenseLineDetail = itemBasedExpenseLineDetail;
				lineObject.Amount = eval(listPrice + '*' + quantity);
				lineArray[0] = lineObject;				
		}else{ // Products is a JSON array
			
				for (var j = 0; j &lt; products.length ; j++) {
					productAttributes = products[j].FL;
					lineObject=eval("({})");					
					for (var i = 0; i &lt; productAttributes.length ; i++) { 	
						if(productAttributes[i].val == "Product Name"){
							productName = productAttributes[i].content;
						}
						
						if(productAttributes[i].val == "List Price"){
							listPrice = productAttributes[i].content;
						}
						if(productAttributes[i].val == "Quantity"){
							quantity = productAttributes[i].content;
						}
						if(productAttributes[i].val == "Product Id"){
							productId = productAttributes[i].content;
						}							
					}
						lineObject.Id = eval('"'+(j+1)+'"');
						lineObject.DetailType = "ItemBasedExpenseLineDetail";
						itemBasedExpenseLineDetail = eval("({})");
						itemBasedExpenseLineDetail.UnitPrice = eval(listPrice);
						itemBasedExpenseLineDetail.Qty = eval(quantity);
						itemBasedExpenseLineDetail.ItemRef = eval("({})");
						itemBasedExpenseLineDetail.ItemRef.name = productName;
						itemBasedExpenseLineDetail.ItemRef.value = productItemMap[productId];
						lineObject.ItemBasedExpenseLineDetail = itemBasedExpenseLineDetail;
						lineObject.Amount = eval(listPrice + '*' + quantity);
						lineArray[j] = lineObject;						
				}			
			}			
			mc.setPayloadJSON(lineArray);						
		</script>
		<property name="qbLine" expression="json-eval($)"/>	
		<!-- Check the availability of Line to proceed with quickbooks API call -->		
		<filter source="boolean(get-property('qbLine'))" regex="false">
			<loopback/>
		</filter>		
		<header name="Expires" scope="transport" action="remove" />
		<header name="Content-Type" scope="transport" action="remove" />
		<header name="Date" scope="transport" action="remove" />
		<header name="Server" scope="transport" action="remove" />
		<header name="Transfer-Encoding" scope="transport" action="remove" />
		<header name="Connection" scope="transport" action="remove" />
		<header name="Vary" scope="transport" action="remove" />
		<header name="Content-Encoding" scope="transport" action="remove" />		
		  <quickbooks.init>
            <consumerKey>{$ctx:qbConsumerKey}</consumerKey>
            <accessToken>{$ctx:qbAccessToken}</accessToken>
            <accessTokenSecret>{$ctx:qbAccessTokenSecret}</accessTokenSecret>
            <responseType>{$ctx:qbResponseType}</responseType>
            <apiUrl>{$ctx:qbApiUrl}</apiUrl>
            <companyId>{$ctx:qbCompanyId}</companyId>
            <consumerSecret>{$ctx:qbConsumerSecret}</consumerSecret>
         </quickbooks.init>
         <quickbooks.createPurchaseOrder>
			<customField>{$ctx:qbCustomField}</customField>
            <attachableRef>{$ctx:qbAttachableRef}</attachableRef>
            <docNumber>{$ctx:qbDocNumber}</docNumber>
            <txnDate>{$ctx:qbTxnDate}</txnDate>
            <privateNote>{$ctx:qbPrivateNote}</privateNote>
            <linkedTxn>{$ctx:qbLinkedTxn}</linkedTxn>
			<line>{$ctx:qbLine}</line>
			<vendorRef>{$ctx:qbVendorRef}</vendorRef>
            <aPAccountRef>{$ctx:qbAPAccountRef}</aPAccountRef>
            <totalAmt>{$ctx:qbTotalAmt}</totalAmt>
			<classRef>{$ctx:qbClassRef}</classRef>
            <salesTermRef>{$ctx:qbSalesTermRef}</salesTermRef>
            <dueDate>{$ctx:qbDueDate}</dueDate>
			<vendorAddr>{$ctx:qbVendorAddr}</vendorAddr>
            <shipAddr>{$ctx:qbShipAddr}</shipAddr>
            <shipMethodRef>{$ctx:qbShipMethodRef}</shipMethodRef>
			<purchaseOrderStatus>{$ctx:qbPurchaseOrderStatus}</purchaseOrderStatus>
            <txnTaxDetail>{$ctx:qbTxnTaxDetail}</txnTaxDetail>
            <taxCodeRef>{$ctx:qbTaxCodeRef}</taxCodeRef>
            <currencyRef>{$ctx:qbCurrencyRef}</currencyRef>
            <exchangeRate>{$ctx:qbExchangeRate}</exchangeRate>
            <globalTaxCalculation>{$ctx:qbGlobalTaxCalculation}</globalTaxCalculation>
         </quickbooks.createPurchaseOrder>		
		<call-template target="responseHandlerTemplate">
			<!-- parameter values will be passed on to a sequence template -->
			(
			<with-param name="activityName" value="quickbooks_createPurchaseOrder" />
			|
			) *
		</call-template>
         <loopback/>
      </inSequence>
      <outSequence>
		<property name="messageType" value="application/json" scope="axis2" />
		<!-- Generate the chained response of all the API calls in createLeads -->
		<payloadFactory media-type="json">
			<format>
				{
				"Response":[$1]
				}
			</format>
			<args>
				<arg expression="get-property('uri.var.responseString')" />
			</args>
		</payloadFactory>		
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>                                                                                  
Sample Request for Creating Purchase Orders in ZohoCRM and QuickBooks
{
	"zohoApiUrl": "https://crm.zoho.com",
	"zohoAccessToken": "b5680e1d2a93d5c184bb3c9ef687cfb8",
	"zohoScope": "crmapi",
	"zohoNewFormat": 2,
	"zohoVersion": 2,
	"zohoXmlData": "<PurchaseOrders><row no=\"1\"><FL val=\"Subject\">PurchaseOrderTestB</FL><FL val=\"Contact Name\">testContactLN</FL><FL val=\"Vendor Name\">Invoice AccountName</FL><FL val=\"Product Name\">Invoice ProductName</FL><FL val=\"Quantity\">10</FL><FL val=\"Unit Price\">2</FL><FL val=\"List Price\">3</FL><FL val=\"Product Details\"><product no=\"1\"><FL val=\"Product Id\">1246886000000084001</FL><FL val=\"Product Name\">testProduct1</FL><FL val=\"Unit Price\">2.0</FL><FL val=\"Quantity\">2.0</FL><FL val=\"Quantity in Stock\">932.0</FL><FL val=\"Total\">4.0</FL><FL val=\"Discount\">1.0</FL><FL val=\"Total After Discount\">3.0</FL><FL val=\"List Price\">1.0</FL><FL val=\"Net Total\">2.0</FL></product><product no=\"2\"><FL val=\"Product Id\">1246886000000084043</FL><FL val=\"Product Name\">testProduct2</FL><FL val=\"Unit Price\">2.0</FL><FL val=\"Quantity\">2.0</FL><FL val=\"Quantity in Stock\">932.0</FL><FL val=\"Total\">4.0</FL><FL val=\"Discount\">1.0</FL><FL val=\"Total After Discount\">3.0</FL><FL val=\"List Price\">1.0</FL><FL val=\"Net Total\">2.0</FL></product></FL></row></PurchaseOrders>",
	"zohoWfTrigger": true,
	"zohoDuplicateCheck": "2",
	"productItemMap":{"1246886000000084001":"26","1246886000000084043":"27"},
	"qbApiUrl":"https://qb.sbfinance.intuit.com:443",
	"qbConsumerKey":"qyprdKxaJQozqIaZO0fMTcRsL7uRgR",
	"qbConsumerSecret":"CnwW5N3HJTB6CLTZem9msH5D5ezq7WGE0THZf7A1",
	"qbAccessToken":"qyprdHCoeAs2Y1ESmoFFCkod7QvjUR3qvVlceq73Lth4qdhL",
	"qbAccessTokenSecret":"aNREf8rnNJRl3PVQT30r5OOzejJWSuF65RRu2WL2",
	"qbResponseType":"application/json",
	"qbCompanyId":"1273577340",
	"qbVendorRef": {"value": "2","name": "John Vendor-UudRGTA2p7"}
}