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

Invoicing in Clio

The third use case in the Clio business scenario is used for invoicing. This page describes the relevant tasks and the operations you use in the Clio connector and the other ESB connectors. 

Overview

The flow for invoicing is illustrated in the following diagram. The ESB connectors for Zoho Books and Clio will be used to connect to each service. ZohoCRM is a customer relationship management software, which could be used for managing deals and its progress. Zoho Books is an online accounting application which can be used to keep track of bills, invoices and payments, etc. 

  1. Retrieve bills awaiting payment from the Clio API using the getBill operation.

  2. Retrieve the matter of the bill from the Clio API using the getMatter operation.
  3. Check if the clients exists in the Zoho Books API getContact operation. If the client does not exist, create the client in the Zoho Books API using the createContact operation.
  4. Update the contact in the Clio API using the updateContact operation. 
  5. Using the createItem operation in the Zoho Books API, create an item which will be used to create an invoice.  Create invoices in the Zoho Books API using the createInvoice operation and email invoices to the client. 
Zoho Books operations
Clio operations
Samples
Sample template for sending emails and/or text messages to recipients
<?xml version="1.0" encoding="UTF-8"?>
<!-- This template sends emails and/or text messages to recipients. -->
<template xmlns="http://ws.apache.org/ns/synapse" name="createInvoice">
	<!-- ZohoBooks parameters -->
	<parameter name="zohobooks.apiUrl" description="Base endpoint URL of ZohoBooks API." />
    <parameter name="zohobooks.authToken" description="OAuth Token to read and manipulate data of ZohoBooks account." />
    <parameter name="zohobooks.organizationId" description="ID of the organization to which the ZohoBooks Account belongs." />
	<parameter name="zohobooks.customerId" description="ID of the customer the invoice has to be created." />
	<parameter name="zohobooks.contactPersons" description="Array of contact person(s) for whom invoice has to be sent." />
	<parameter name="zohobooks.billIssuedDate" description="Issued bill date." />
	<parameter name="zohobooks.billDueAt" description="Payment due date for the bill." />
	<parameter name="zohobooks.itemName" description="Payment due date for the bill." />
	<parameter name="zohobooks.itemDescription" description="Payment due date for the bill." />
	<parameter name="zohobooks.billTotal" description="Bill total." />
	
    <sequence>
        <!-- ZohoBooks properties. -->
		<property name="uri.var.zohobooks.apiUrl" expression="$func:zohobooks.apiUrl" />
        <property name="uri.var.zohobooks.authToken" expression="$func:zohobooks.authToken" />
        <property name="uri.var.zohobooks.organizationId" expression="$func:zohobooks.organizationId" />
		<property name="uri.var.zohobooks.customerId" expression="$func:zohobooks.customerId" />
		<property name="uri.var.zohobooks.contactPersons" expression="$func:zohobooks.contactPersons" />
		<property name="uri.var.zohobooks.billIssuedDate" expression="$func:zohobooks.billIssuedDate" />
		<property name="uri.var.zohobooks.billDueAt" expression="$func:zohobooks.billDueAt" />
		<property name="uri.var.zohobooks.itemName" expression="$func:zohobooks.itemName" />
		<property name="uri.var.zohobooks.itemDescription" expression="$func:zohobooks.itemDescription" />
		<property name="uri.var.zohobooks.billTotal" expression="$func:zohobooks.billTotal" />
		
        <!-- Create an item in ZohoBooks - Executed only if both authToken and organizationId of ZohoBooks is sent. -->
        <filter xpath="boolean(get-property('uri.var.zohobooks.authToken')) and boolean(get-property('uri.var.zohobooks.organizationId'))">
            <then>
				<!-- Create an item with the bill information. -->
				<zohobooks.init>
					<apiUrl>{$ctx:uri.var.zohobooks.apiUrl}</apiUrl>
					<authToken>{$ctx:uri.var.zohobooks.authToken}</authToken>
					<organizationId>{$ctx:uri.var.zohobooks.organizationId}</organizationId>
				</zohobooks.init>
				<zohobooks.createItem>
					<itemName>{$ctx:uri.var.zohobooks.itemName}</itemName>
					<description>{$ctx:uri.var.zohobooks.itemDescription}</description>
					<rate>{$ctx:uri.var.zohobooks.billTotal}</rate>
				</zohobooks.createItem>
                <sequence key="removeResponseHeaders" />
				
				<!-- Extract the item details. -->
                <property name="zohoBooks.itemId" expression="json-eval($.item.item_id)" />
				<property name="zohoBooks.itemName" expression="json-eval($.item.name)" />
				<property name="zohoBooks.itemDescription" expression="json-eval($.item.description)" />
				
				<property name="clio.invloiceItems" expression="fn:concat('[{&quot;item_id&quot;:&quot;',get-property('zohoBooks.itemId'),'&quot;,&quot;name&quot;:&quot;',get-property('zohoBooks.itemName'),'&quot;,&quot;description&quot;:&quot;',get-property('zohoBooks.itemDescription'),'&quot;,&quot;item_total&quot;:',get-property('clio.billTotal'),'}]')" />
				
                <!-- If the item is not created successfully, send an error message with the API error response. -->
                <filter source="boolean(get-property('zohoBooks.itemId'))" regex="false">
                    <then>
                        <!-- Message to be sent if contact was not created in zohoBooks. -->
						<property name="id" expression="fn:concat('clio.matterDisplayId:', get-property('clio.matterDisplayId'))" />
						<property name="status" value="Failed" />
						<property name="message" value="Fail to create an item in ZohoBooks." />
						<!-- Call responseHandler template. -->
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="zohobooks_createItem" />
							<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="uri.var.zohoBooks.contactPersonsId" expression="fn:concat('[&quot;',get-property('uri.var.zohobooks.contactPersons'),'&quot;]')" />
					
						<zohobooks.init>
							<apiUrl>{$ctx:uri.var.zohobooks.apiUrl}</apiUrl>
							<authToken>{$ctx:uri.var.zohobooks.authToken}</authToken>
							<organizationId>{$ctx:uri.var.zohobooks.organizationId}</organizationId>
						</zohobooks.init>
						<zohobooks.createInvoice>
							<customerId>{$ctx:uri.var.zohobooks.customerId}</customerId>
							<contactPersons>{$ctx:uri.var.zohoBooks.contactPersonsId}</contactPersons>
							<date>{$ctx:uri.var.zohobooks.billIssuedDate}</date>
							<dueDate>{$ctx:uri.var.zohobooks.billDueAt}</dueDate>
							<lineItems>{$ctx:clio.invloiceItems}</lineItems>
							<send>true</send>
							<ignoreAutoNumberGeneration>false</ignoreAutoNumberGeneration>
						</zohobooks.createInvoice>
                        <sequence key="removeResponseHeaders" />
                        
						<property name="zohoBooks.invoiceId" expression="json-eval($.invoice.invoice_id)" />
									 
						<!-- Verify zohoBooks contact id is updated in Clio. -->
						<filter source="boolean(get-property('zohoBooks.invoiceId'))" regex="false">
							<then>
								<!-- Message to be sent if contact was not created in zohoBooks. -->
								<property name="id" expression="fn:concat('zohoBooks.itemId:', get-property('zohoBooks.itemId'))" />
								<property name="status" value="Failed" />
								<property name="message" value="Fail to create an invoice in ZohoBooks Successfully." />
								<!-- Call responseHandler template -->
								<call-template target="responseHandlerTemplate">
									<with-param name="activity" value="zohobooks_createInvoice" />
									<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>
								<!-- Message to be sent if contact was not created in zohoBooks. -->
								<property name="id" expression="fn:concat('zohobooks.invoiceId:', get-property('zohoBooks.invoiceId'))" />
								<property name="status" value="Success" />
								<property name="message" value="Invoice has been generated successfully in ZohoBooks" />
								<!-- Call responseHandler template. -->
								<call-template target="responseHandlerTemplate">
									<with-param name="activity" value="zohobooks_createInvoice" />
									<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>
                    </else>
                </filter>
            </then>
        </filter>
    </sequence>
</template>
Sample proxy for creating a contact in Zoho Books for the owner of the Bill (in Clio)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="clio_sendInvoiceDetailsToClients" transports="https,http"
   statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <sequence key="scenarioConstants" />
         <!-- Clio parameters. -->
         <property name="clio.apiUrl" expression="json-eval($.clioApiUrl)" />
         <property name="clio.accessToken" expression="json-eval($.clioAccessToken)" />
         <!-- Zoho Books parameters. -->
         <property name="zohoBooks.apiUrl" expression="json-eval($.zohoBooksApiUrl)" />
         <property name="zohoBooks.authToken" expression="json-eval($.zohoBooksAuthToken)" />
         <property name="zohoBooks.organizationId" expression="json-eval($.zohoBooksOrganizationId)" />
		 <!-- Operation scoped properties -->
         <property name="responseString" value="" scope="operation" />
         <property name="activityName" value="clio_sendInvoiceDetailsToClients" scope="operation" />
         <property name="noOfBills" expression="count(//jsonObject/clioBillIds)" scope="operation" />
         <property name="billIndex" expression="0" scope="operation" />
         <!--START: Proceed with the scenario only if at least one Clio contactID is provided. -->
         <filter source="get-property('operation', 'noOfBills')" regex="0.0">
            <then>
               <payloadFactory media-type="json">
                  <format>{
                     "Response":{
						 "activity":"clio_sendInvoiceDetailsToClients",
						 "activityResponse":"clioBillIds array is empty - No entries to process."
						 }
                     }
                  </format>
               </payloadFactory>
               <respond />
            </then>
            <else>
               <!--FOR EACH Clio Bill ID given in the Array: BEGIN -->
               <iterate continueParent="false" id="noteKeys" expression="//jsonObject/clioBillIds" sequential="true">
                  <target>
                     <sequence>
						<property name="clio.billId" expression="//clioBillIds/text()" />
						
						<!-- Retrieve bill details from Clio. -->
					 <clio.init>
						<apiUrl>{$ctx:clio.apiUrl}</apiUrl>
						<accessToken>{$ctx:clio.accessToken}</accessToken>
					 </clio.init>
					 <clio.getBill>
						<billId>{$ctx:clio.billId}</billId>
					 </clio.getBill>
					 <sequence key="removeResponseHeaders" />
					 <property name="clio.billId" expression="//jsonObject/bill/id/text()" />
					 <!-- START: Proceed with the scenario only if the bill was found in Clio. -->
					 <filter source="get-property('clio.billId')" regex="false">
						<then>
						   <property name="id" expression="fn:concat('clio_billId:', get-property('clio.billId'))" />
						   <property name="status" value="Failure" />
						   <property name="errorResponse" expression="json-eval($)" />
						   <!-- Call responseHandler template. -->
						   <call-template target="responseHandlerTemplate">
							  <with-param name="activity" value="clio_getBill" />
							  <with-param name="id" value="{$ctx:id}" />
							  <with-param name="status" value="{$ctx:status.failure}" />
							  <with-param name="message" value="{$ctx:errorResponse}" />
						   </call-template>
						</then>
						<else>
						   <property name="clio.clientId" expression="//jsonObject/bill/client/id/text()" />
						   <property name="clio.billTotal" expression="//jsonObject/bill/total/text()" />
						   <property name="clio.matterId" expression="//jsonObject/bill/matters/id/text()" />
						   <property name="clio.billIssued" expression="//jsonObject/bill/issued_at/text()" />
						   <property name="clio.billDueAt" expression="//jsonObject/bill/due_at/text()" />
						   <!-- Retrieve the matter details related to your bill from Clio. -->
						   <clio.init>
							  <apiUrl>{$ctx:clio.apiUrl}</apiUrl>
							  <accessToken>{$ctx:clio.accessToken}</accessToken>
						   </clio.init>
						   <clio.getMatter>
							  <matterId>{$ctx:clio.matterId}</matterId>
						   </clio.getMatter>
						   <sequence key="removeResponseHeaders" />
						   <property name="clio.matterDisplayId" expression="//jsonObject/matter/display_number/text()" />
						   <property name="clio.matterDescription" expression="//jsonObject/matter/description/text()" />
						   <!-- START: Checking the existence of matter details in Clio to proceed. -->
						   <filter source="boolean(get-property('clio.matterDisplayId'))" regex="false">
							  <then>
								 <property name="id" expression="fn:concat('clio_matterId:', get-property('clio.matterId'))" />
								 <property name="errorResponse" expression="json-eval($)" />
								 <!-- Call responseHandler template -->
								 <call-template target="responseHandlerTemplate">
									<with-param name="activity" value="clio_getMatter" />
									<with-param name="id" value="{$ctx:id}" />
									<with-param name="status" value="{$ctx:status.failure}" />
									<with-param name="message" value="{$ctx:errorResponse}" />
								 </call-template>
							  </then>
							  <else>
								 <!-- Retrieve contact details using client ID from Clio. -->
								 <clio.init>
									<apiUrl>{$ctx:clio.apiUrl}</apiUrl>
									<accessToken>{$ctx:clio.accessToken}</accessToken>
								 </clio.init>
								 <clio.getContact>
									<contactId>{$ctx:clio.clientId}</contactId>
								 </clio.getContact>
								 <sequence key="removeResponseHeaders" />
								 <property name="clio.customFieldArray" expression="json-eval($.contact.custom_field_values)" />
								 <!-- Script Mediator to iterate through the custom fields and extract the required
									note key. -->
								 <script language="js">
																  <![CDATA[														 
																	 var customFieldArray = eval("(" + mc.getProperty('clio.customFieldArray') + ")");
																	 var zohobooksCustomFieldName = mc.getProperty('clio.zohobooksCustomFieldName');
																	 var zohobooksContactPersonCustomFieldName = mc.getProperty('clio.zohobooksContactPersonCustomFieldName');
																	 
																	 for(var i=0; i<customFieldArray.length; i++){
																		if(customFieldArray[i].custom_field.name.toLowerCase() == zohobooksCustomFieldName.toLowerCase()){
																			// Set the zohoBooksContactId to a property
																			mc.setProperty('clio.zohoBooksContactId', customFieldArray[i].value);																			
																		} else if (customFieldArray[i].custom_field.name.toLowerCase() == zohobooksContactPersonCustomFieldName.toLowerCase()) {
																			// Set the zohoBooksContactPersonId to a property
																			mc.setProperty('clio.zohoBooksContactPersonId', customFieldArray[i].value);	
																		}
																	 }												   
																  ]]>
								 </script>
								 <!-- START: If the contact doesn't exist in ZohoBooks, create the contact. -->
								 <filter source="boolean(get-property('clio.zohoBooksContactId'))
													and boolean(get-property('clio.zohoBooksContactPersonId'))" regex="false">
									<then>
									   <property name="clio.webSite" expression="//jsonObject/contact/web_sites/address/text()" />
									   <property name="clio.contactName" expression="//jsonObject/contact/name/text()" />
									   <!-- Extracting clio contact details. -->
									   <property name="clio.prefix" expression="//jsonObject/contact/prefix/text()" />
									   <property name="clio.firstName" expression="//jsonObject/contact/first_name/text()" />
									   <property name="clio.lastName" expression="//jsonObject/contact/last_name/text()" />
									   <property name="clio.email" expression="//jsonObject/contact/email_addresses/address/text()" />
									   <property name="clio.phone" expression="//jsonObject/contact/phone_numbers/number/text()" />
									   <!-- Extracting clio billing address details. -->
									   <property name="clio.address" expression="//jsonObject/contact/addresses/street/text()" />
									   <property name="clio.city" expression="//jsonObject/contact/addresses/city/text()" />
									   <property name="clio.province" expression="//jsonObject/contact/addresses/province/text()" />
									   <property name="clio.postalCode" expression="//jsonObject/contact/addresses/postal_code/text()" />
									   <property name="clio.country" expression="//jsonObject/contact/addresses/country/text()" />
									   <!-- Constructing the zohoBooks contactPersons field value. -->
									   <property name="zohoBooks.contactPersons"
										  expression="fn:concat('[{&quot;salutation&quot;:&quot;', get-property('clio.prefix'), '&quot;,&quot;first_name&quot;:&quot;', get-property('clio.firstName'),'&quot;,&quot;last_name&quot;:&quot;', get-property('clio.lastName'),'&quot;,&quot;email&quot;:&quot;', get-property('clio.email'),'&quot;,&quot;phone&quot;:&quot;', get-property('clio.phone'),'&quot;,&quot;is_primary_contact&quot;:true}]')" />
									   <!-- Constructing the zohoBooks billingAddress field value. -->
									   <property name="zohoBooks.billingAddress"
										  expression="fn:concat('{&quot;address&quot;:&quot;', get-property('clio.address'), '&quot;,&quot;city&quot;:&quot;', get-property('clio.city'),'&quot;,&quot;state&quot;:&quot;', get-property('clio.province'),'&quot;,&quot;zip&quot;:&quot;', get-property('clio.postalCode'),'&quot;,&quot;country&quot;:&quot;', get-property('clio.country'),'&quot;}')" />
									   <!-- Create contact in ZohoBooks -->
									   <zohobooks.init>
										  <apiUrl>{$ctx:zohoBooks.apiUrl}</apiUrl>
										  <authToken>{$ctx:zohoBooks.authToken}</authToken>
										  <organizationId>{$ctx:zohoBooks.organizationId}</organizationId>
									   </zohobooks.init>
									   <zohobooks.createContact>
										  <isPrimaryContact>true</isPrimaryContact>
										  <email>{$ctx:email}</email>
										  <contactPersons>{$ctx:zohoBooks.contactPersons}</contactPersons>
										  <billingAddress>{$ctx:zohoBooks.billingAddress}</billingAddress>
										  <website>{$ctx:clio.webSite}</website>
										  <contactName>{$ctx:clio.contactName}</contactName>
									   </zohobooks.createContact>
									   <sequence key="removeResponseHeaders" />
									   <property name="clio.zohoBooksContactId" expression="//jsonObject/contact/contact_id/text()" />
									   <property name="clio.zohoBooksContactPersonId" expression="//jsonObject/contact/contact_persons/contact_person_id/text()" />
									   <!-- START: Checking the existence of contact id in zohoBooks createContact response. -->
									   <filter source="boolean(get-property('clio.zohoBooksContactId'))" regex="false">
										  <then>
											 <!-- Message to be sent if contact was not created in zohoBooks. -->
											 <property name="id"
												expression="fn:concat('clio_contactName:', get-property('clio.contactName'))" />
											 <property name="errorResponse" expression="json-eval($)" />
											 <!-- Call responseHandler template. -->
											 <call-template target="responseHandlerTemplate">
												<with-param name="activity" value="zohobooks_createContact" />
												<with-param name="id" value="{$ctx:id}" />
												<with-param name="status" value="{$ctx:status.failure}" />
												<with-param name="message" value="{$ctx:errorResponse}" />
											 </call-template>
										  </then>
										  <else>
											 <!-- Message to be sent if a contact was created in zohoBooks. -->
											 <property name="id"
												expression="fn:concat('zohoBooks_contactId:', get-property('clio.zohoBooksContactId'))" />
											 <!-- Call responseHandler template. -->
											 <call-template target="responseHandlerTemplate">
												<with-param name="activity" value="zohobooks_createContact" />
												<with-param name="id" value="{$ctx:id}" />
												<with-param name="status" value="{$ctx:status.success}" />
												<with-param name="message" value="{$ctx:message.zohobooks.contactCreated}" />
											 </call-template>
											 <!--Call the getCustomFieldId to get the ID of the Custom Field -->
											 <call-template target="getCustomFieldId">
												<with-param name="apiUrl" value="{$ctx:clio.apiUrl}" />
												<with-param name="accessToken" value="{$ctx:clio.accessToken}" />
												<with-param name="customFieldName" value="{$ctx:clio.zohobooksCustomFieldName}" />
											 </call-template>
											 
											 <property name="clio.zohoBooksContactCustomFieldId" expression="get-property('clio.customFieldId')" />
											 
											 <!--Call the getCustomFieldId to get the ID of the Custom Field -->
											 <call-template target="getCustomFieldId">
												<with-param name="apiUrl" value="{$ctx:clio.apiUrl}" />
												<with-param name="accessToken" value="{$ctx:clio.accessToken}" />
												<with-param name="customFieldName" value="{$ctx:clio.zohobooksContactPersonCustomFieldName}" />
											 </call-template>
											 
											 <property name="clio.zohoBooksContactPersonCustomFieldId" expression="get-property('clio.customFieldId')" />
											 <!-- Constructing the Clio contact custom field value. -->
											 <property name="clio.updateZohoBooksContactId"
												expression="fn:concat('[{&quot;custom_field&quot;:{&quot;id&quot;:', get-property('clio.zohoBooksContactCustomFieldId'),'},&quot;value&quot;:&quot;', get-property('clio.zohoBooksContactId'),'&quot;},
																		{&quot;custom_field&quot;:{&quot;id&quot;:', get-property('clio.zohoBooksContactPersonCustomFieldId'),'},&quot;value&quot;:&quot;', get-property('clio.zohoBooksContactPersonId'),'&quot;}]')" />
											 <!-- Update zohoBooks custom field contact Id in Clio. -->
											 <clio.init>
												<apiUrl>{$ctx:clio.apiUrl}</apiUrl>
												<accessToken>{$ctx:clio.accessToken}</accessToken>
											 </clio.init>
											 <clio.updateContact>
												<contactId>{$ctx:clio.clientId}</contactId>
												<customFieldValues>{$ctx:clio.updateZohoBooksContactId}</customFieldValues>
											 </clio.updateContact>
											 <sequence key="removeResponseHeaders" />
											 <property name="clio.updatedZohoBooksContactId" expression="//jsonObject/contact/custom_field_values/value/text()" />
											 <!-- Verify zohoBooks contact id is updated in Clio. -->
											 <filter
												xpath="get-property('zohoBooks.contactId') != get-property('clio.updatedZohoBooksContactId')">
												<then>
												   <!-- Message to be sent if contact was not created in zohoBooks. -->
												   <property name="id"
													  expression="fn:concat('clio_contactId:', get-property('clio.clientId'),'zohobooks_contactId:', get-property('zohoBooks.contactId'))" />
												   <!-- Call responseHandler template. -->
												   <call-template target="responseHandlerTemplate">
													  <with-param name="activity" value="zohobooks_updateContact" />
													  <with-param name="id" value="{$ctx:id}" />
													  <with-param name="status" value="{$ctx:status.failure}" />
													  <with-param name="message" value="{$ctx:message.zohobooks.customFieldUpdateFailed}" />
												   </call-template>
												</then>
											 </filter>
											 <!-- Create an item and generate the invoice with the bill information. -->
											 <call-template target="createInvoice">
												<with-param name="zohobooks.apiUrl" value="{$ctx:zohoBooks.apiUrl}" />
												<with-param name="zohobooks.authToken" value="{$ctx:zohoBooks.authToken}" />
												<with-param name="zohobooks.organizationId" value="{$ctx:zohoBooks.organizationId}" />
												<with-param name="zohobooks.customerId" value="{$ctx:clio.zohoBooksContactId}" />
												<with-param name="zohobooks.contactPersons" value="{$ctx:clio.zohoBooksContactPersonId}" />
												<with-param name="zohobooks.billIssuedDate" value="{$ctx:clio.billIssued}" />
												<with-param name="zohobooks.billDueAt" value="{$ctx:clio.billDueAt}" />
												<with-param name="zohobooks.itemName" value="{$ctx:clio.matterDisplayId}" />
												<with-param name="zohobooks.itemDescription" value="{$ctx:clio.matterDescription}" />
												<with-param name="zohobooks.billTotal" value="{$ctx:clio.billTotal}" />
											 </call-template>
										  </else>
									   </filter>
									   <!-- END: Checking the existence of contact id in zohoBooks createContact response. -->
									</then>
									<else>
									   <!-- Retrieve contact details from ZohoBooks using zohobooks contact id from Clio. -->
									   <zohobooks.init>
										  <apiUrl>{$ctx:zohoBooks.apiUrl}</apiUrl>
										  <authToken>{$ctx:zohoBooks.authToken}</authToken>
										  <organizationId>{$ctx:zohoBooks.organizationId}</organizationId>
									   </zohobooks.init>
									   <zohobooks.getContact>
										  <contactId>{$ctx:clio.zohoBooksContactId}</contactId>
									   </zohobooks.getContact>
									   <sequence key="removeResponseHeaders" />
									   <property name="zohoBooks.contactId" expression="//jsonObject/contact/contact_id/text()" />
									   <property name="zohoBooks.contactPersonId" expression="//jsonObject/contact/contact_persons/contact_person_id/text()" />
									   <!-- START: Verify zohoBooks contact id is updated in Clio. -->
									   <filter source="boolean(get-property('zohoBooks.contactId'))" regex="false">
										  <then>
											 <!-- Message to be sent if contact was not created in zohoBooks. -->
											 <property name="id"
												expression="fn:concat('clio_zohoBooksContactId:', get-property('clio.zohoBooksContactId'))" />
											 <!-- Call responseHandler template. -->
											 <call-template target="responseHandlerTemplate">
												<with-param name="activity" value="zohobooks_getContact" />
												<with-param name="id" value="{$ctx:id}" />
												<with-param name="status" value="{$ctx:status.failure}" />
												<with-param name="message" value="{$ctx:message.zohobooks.customerMissing}" />
											 </call-template>
										  </then>
										  <else>
											 <!-- Create an item and generate the invoice with the bill information. -->
											 <call-template target="createInvoice">
												<with-param name="zohobooks.apiUrl" value="{$ctx:zohoBooks.apiUrl}" />
												<with-param name="zohobooks.authToken" value="{$ctx:zohoBooks.authToken}" />
												<with-param name="zohobooks.organizationId" value="{$ctx:zohoBooks.organizationId}" />
												<with-param name="zohobooks.customerId" value="{$ctx:zohoBooks.contactId}" />
												<with-param name="zohobooks.contactPersons" value="{$ctx:zohoBooks.contactPersonId}" />
												<with-param name="zohobooks.billIssuedDate" value="{$ctx:clio.billIssued}" />
												<with-param name="zohobooks.billDueAt" value="{$ctx:clio.billDueAt}" />
												<with-param name="zohobooks.itemName" value="{$ctx:clio.matterDisplayId}" />
												<with-param name="zohobooks.itemDescription" value="{$ctx:clio.matterDescription}" />
												<with-param name="zohobooks.billTotal" value="{$ctx:clio.billTotal}" />
											 </call-template>
										  </else>
									   </filter>
									   <!-- END: Verify zohoBooks contact id is updated in Clio. -->
									</else>
								 </filter>
								 <!-- END: If the contact doesn't exist in ZohoBooks, create the contact. -->
							  </else>
						   </filter>
						   <!-- END: Checking the existence of matter details in Clio to proceed. -->
						</else>
					 </filter>
					 <!-- END: Proceed with the scenario only if the bill was found in Clio. -->
					 
					 <!--Increment the Bill Count -->
                     <property name="billIndex" expression="get-property('operation','billIndex') + 1"
                           scope="operation" />
                     </sequence>
                  </target>
               </iterate>
               <!--FOR EACH Clio Bill ID given in the Array: BEGIN -->
               <filter xpath="get-property('operation', 'billIndex') = get-property('operation', 'noOfBills')">
                  <then>
                     <loopback />
                  </then>
               </filter>
            </else>
         </filter>
         <!--END: Proceed with the scenario only if at least one Clio contactID is provided. -->
		 
         
         <loopback />
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{
               "Response":{
               "process":"clio_sendInvoiceDetailsToClients",
               "activityResponse":[$1]
               }
               }
            </format>
            <args>
               <arg expression="get-property('operation','responseString')" />
            </args>
         </payloadFactory>
         <property name="messageType" value="application/json" scope="axis2" />
         <send />
      </outSequence>
   </target>
   <description />
</proxy>
Sample request for creating a contact in Zoho Books for the owner of the Bill (in Clio)
{
    "clioApiUrl": "https://app.goclio.com",
    "clioAccessToken": "fL9aZC3k6wprSqVtlfuowat1JMXX9WazGyQCkQzG",
    "clioBillIds": ["11585777","11585781","11585785"],
    "zohoBooksApiUrl": "https://books.zoho.com",
    "zohoBooksAuthToken": "e9199d6b1779aa8fe0103e0e56f402bb",
    "zohoBooksOrganizationId": "48120746"
}