Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Overview

The flow for managing orders is illustrated in the following diagram. The ESB connectors for ZohoCRM 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 ZohoCRM using insertRecords.
  2. Retrieve items from QuickBooks using the   query operation, and then create products in ZohoCRM using the  insertRecords operation.
  3. Create purchase orders for the vendors and products in ZohoCRM 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 ZohoCRM. 
ZohoCRM operations
QuickBooks operations

Samples

Info

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

Code Block
languagexml
titleSample Template for Creating and Retrieving Purchase Orders
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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>
Code Block
languagexml
titleSample Proxy for Creating ZohoCRM Vendors Using the QuickBooks Vendors
<?xml version="1.0" encoding="UTF-8"?>
<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>                                                                                          

...

Code Block
languagexml
titleSample Proxy for Creating ZohoCRM Products Using the QuickBooks Items
<?xml version="1.0" encoding="UTF-8"?>
<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>                                                                                                            

...

Code Block
languagexml
titleSample Proxy for Creating Purchase Orders in ZohoCRM and QuickBooks
<?xml version="1.0" encoding="UTF-8"?>
<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>                                                                                  

...