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

Matter Initiation in Clio

The first use case in the Clio business scenario is used for matter initiation. This page describes the relevant tasks and the operations you use in the Clio connector and the other ESB connectors. It contains the following sections:

Overview

The flow for matter initiation is illustrated in the following diagram. The ESB connectors for Zoho CRM, Clio, and Simplenote 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. Simplenote can be used to keep track of  notes and its progress. 

Prerequisite

Contacts who need legal assistance should have it mentioned in the description column in Zoho CRM as an offline ESB task.

Creating contacts

  1. Retrieve selected contacts from the Zoho CRM using the getRecordById operation. 

  2. Using the createContact operation create contacts in the Clio API. There is no way to avoid duplicates if the user directly creates the contact in the Clio API by sending the identical set of data.

  3. Using the updateRecords operation in Zoho CRM, update the custom field of the contact with the Clio contact ID so that the contact is not duplicated in successive calls.

  4. Using the updateContact operation, update the custom field of the contact with the Simplenote note key.

  5. Create a tag for the contact in the Simplenote API using the createTag operation.

  6. Create a note under the above created tag and make it the active note for the contact in the Simplenote API using the createNote operation. Initially the note would contain some default content. 
Zoho CRM operations
Clio operations
Simplenote operations
Samples
Sample template for creating contacts in Clio, updating contacts record in Zoho CRM and creating tags in Simplenote
<?xml version="1.0" encoding="UTF-8"?>
<!-- This template creates contacts in Clio, updates contacts record in ZohoCRM and create tag in SimpleNote. -->
<template xmlns="http://ws.apache.org/ns/synapse" name="createContactAndTag">
   <!-- Clio parameters -->
   <parameter name="clio.apiUrl" description="Base endpoint URL of Clio API." />
   <parameter name="clio.accessToken" description="OAuth Token to read and manipulate data of Clio account." />
   <parameter name="clio.addresses" description="Collection of mailing addresses." />
   <parameter name="clio.instantMessengers" description="Collection of instant messengers' addresses of the Contact." />
   <parameter name="clio.firstName" description="Person's given name." />
   <parameter name="clio.lastName" description="Person's surname." />
   <parameter name="clio.title" description="Person's title." />
   <parameter name="clio.prefix" description="Person's prefix (e.g. Mr, Mrs, etc)." />
   <parameter name="clio.phoneNumbers" description="Collection of phone numbers. The first phone number listed is the default." />
   <parameter name="clio.emailAddresses" description="Collection of email addresses of the Contact." />
   <!-- ZohoCRM parameters -->
   <parameter name="zohocrm.apiUrl" description="The url to access ZohoCRM api." />
   <parameter name="zohocrm.accessToken" description="Encrypted alphanumeric string to authenticate the Zoho credentials" />
   <parameter name="zohocrm.id" description="The identifier of the record being updated" />
   <parameter name="zohocrm.clioContactId" description="The custom field in ZohoCRM which indicates whether the Clio contact ID is stored or not." />
   <parameter name="zohocrm.isContactFromZohoCrm" description="Indicates whether or not the Contact is retrieved from ZohoCRM." />
   <!-- SimpleNote parameters -->
   <parameter name="simplenote.apiUrl" description="Base endpoint URL of SimpleNote API." />
   <parameter name="simplenote.authToken" description="OAuth Token to read and manipulate data of SimpleNote account." />
   <parameter name="simplenote.email" description="Email address of the authorized account." />
   <sequence>
      <!-- Clio properties -->
      <property name="uri.var.clio.apiUrl" expression="$func:clio.apiUrl" />
      <property name="uri.var.clio.accessToken" expression="$func:clio.accessToken" />
      <property name="uri.var.clio.addresses" expression="$func:clio.addresses" />
      <property name="uri.var.clio.instantMessengers" expression="$func:clio.instantMessengers" />
      <property name="uri.var.clio.firstName" expression="$func:clio.firstName" />
      <property name="uri.var.clio.lastName" expression="$func:clio.lastName" />
      <property name="uri.var.clio.title" expression="$func:clio.title" />
      <property name="uri.var.clio.prefix" expression="$func:clio.prefix" />
      <property name="uri.var.clio.phoneNumbers" expression="$func:clio.phoneNumbers" />
      <property name="uri.var.clio.emailAddresses" expression="$func:clio.emailAddresses" />
      <!-- ZohoCRM properties -->
      <property name="uri.var.zohocrm.apiUrl" expression="$func:zohocrm.apiUrl" />
      <property name="uri.var.zohocrm.accessToken" expression="$func:zohocrm.accessToken" />
      <property name="uri.var.zohocrm.id" expression="$func:zohocrm.id" />
      <property name="uri.var.zohocrm.clioContactId" expression="$func:zohocrm.clioContactId" />
      <property name="uri.var.zohocrm.isContactFromZohoCrm" expression="$func:zohocrm.isContactFromZohoCrm" />
      <!-- SimpleNote properties -->
      <property name="uri.var.simplenote.authToken" expression="$func:simplenote.authToken" />
      <property name="uri.var.simplenote.email" expression="$func:simplenote.email" />
      <property name="uri.var.simplenote.apiUrl" expression="$func:simplenote.apiUrl" />
      <!--Check whether the contact is already existing or not -->
      <filter source="boolean(get-property('uri.var.zohocrm.clioContactId'))" regex="true">
         <!--If contact exists then display a custom error message -->
         <then>
            <property name="id" expression="fn:concat('zohocrm_contactId:', get-property('uri.var.zohocrm.id'))" />
            <!--Call the responseHandler template -->
            <call-template target="responseHandlerTemplate">
               <with-param name="activity" value="clio_createContact" />
               <with-param name="id" value="{$ctx:id}" />
               <with-param name="status" value="{$ctx:status.skipped}" />
               <with-param name="message" value="{$ctx:message.existingContact}" />
            </call-template>
         </then>
         <else>
            <!-- Clio API Requirement: Ensure that the Content-Type header is application/json -->
            <header name="Content-Type" value="application/json" scope="transport" />
            <!--Create a Contact in Clio with the given details -->
            <clio.init>
               <apiUrl>{$ctx:uri.var.clio.apiUrl}</apiUrl>
               <accessToken>{$ctx:uri.var.clio.accessToken}</accessToken>
            </clio.init>
            <clio.createContact>
               <contactType>Person</contactType>
               <addresses>{$ctx:uri.var.clio.addresses}</addresses>
               <instantMessengers>{$ctx:uri.var.clio.instantMessengers}</instantMessengers>
               <firstName>{$ctx:uri.var.clio.firstName}</firstName>
               <lastName>{$ctx:uri.var.clio.lastName}</lastName>
               <title>{$ctx:uri.var.clio.title}</title>
               <prefix>{$ctx:uri.var.clio.prefix}</prefix>
               <phoneNumbers>{$ctx:uri.var.clio.phoneNumbers}</phoneNumbers>
               <emailAddresses>{$ctx:uri.var.clio.emailAddresses}</emailAddresses>
            </clio.createContact>
            <sequence key="removeResponseHeaders" />
            <!-- Extract the id and the firstName from Clio response. -->
            <property name="uri.var.clio.contactId" expression="json-eval($.contact.id)" />
            <property name="uri.var.clio.contactFirstName" expression="json-eval($.contact.first_name)" />
            <property name="uri.var.clio.contactLastName" expression="json-eval($.contact.last_name)" />
            <filter source="boolean(get-property('uri.var.clio.contactId'))" regex="false">
               <!-- If creation of contact is unsuccessful then display a custom generated error message -->
               <then>
                  <property name="apiErrorResponse" expression="json-eval($.message)" />
                  <!--Call the responseHandler template -->
                  <call-template target="responseHandlerTemplate">
                     <with-param name="activity" value="clio_createContact" />
                     <with-param name="id" value="{$ctx:id.empty}" />
                     <with-param name="status" value="{$ctx:status.failure}" />
                     <with-param name="message" value="{$ctx:apiErrorResponse}" />
                  </call-template>
               </then>
               <else>
                  <property name="id" expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'))" />
                  <!--Call the responseHandler template -->
                  <call-template target="responseHandlerTemplate">
                     <with-param name="id" value="{$ctx:id}" />
                     <with-param name="activity" value="clio_createContact" />
                     <with-param name="status" value="{$ctx:status.success}" />
                     <with-param name="message" value="{$ctx:message.contactCreated}" />
                  </call-template>
                  <!--START: If the contact is retrieved from ZohoCrm then update the custom field with the Clio contact
                     Id -->
                  <filter source="get-property('uri.var.zohocrm.isContactFromZohoCrm')" regex="true">
                     <then>
                        <script language="js"><![CDATA[
							  
								//constructing the xml data in order to update the contact in ZohoCrm								
								var clioContactId=mc.getProperty('uri.var.clio.contactId');								
								var xmlData="<Contacts> <row no=\"1\"> <FL val=\"Clio Contact ID\">"+clioContactId+"</FL> </row> </Contacts>";
								
								mc.setProperty('uri.var.zohocrm.xmlData', xmlData);
								]]></script>
                        <!-- Update custom field of contact in ZohoCRM -->
                        <zohocrm.init>
                           <apiUrl>{$ctx:uri.var.zohocrm.apiUrl}</apiUrl>
                           <accessToken>{$ctx:uri.var.zohocrm.accessToken}</accessToken>
                           <scope>crmapi</scope>
                        </zohocrm.init>
                        <zohocrm.updateRecords>
                           <moduleType>Contacts</moduleType>
                           <id>{$ctx:uri.var.zohocrm.id}</id>
                           <xmlData>{$ctx:uri.var.zohocrm.xmlData}</xmlData>
                        </zohocrm.updateRecords>
                        <sequence key="removeResponseHeaders" />
                        <property name="uri.var.zohocrm.contactId" expression="json-eval($.response.result.recorddetail.FL[0].content)" />
                        <filter source="boolean(get-property('uri.var.zohocrm.contactId'))" regex="false">
                           <then>
                              <property name="id"
                                 expression="fn:concat('zohocrm_contactId:', get-property('uri.var.zohocrm.id'))" />
                              <!--Call the responseHandler template -->
                              <call-template target="responseHandlerTemplate">
                                 <with-param name="activity" value="zohocrm_updateRecords" />
                                 <with-param name="id" value="{$ctx:id}" />
                                 <with-param name="status" value="{$ctx:status.failure}" />
                                 <with-param name="message" value="{$ctx:message.zohocrmUpdateFailed}" />
                              </call-template>
                           </then>
                        </filter>		<!--END of filter: Checking the successful update in zohoCRM -->
                     </then>
                  </filter>
                  <!--START: If the contact is retrieved from ZohoCrm then update the custom field with the Clio contact
                     Id -->
                  <!-- Create a tag in SimpleNote for the contact -->
                  <property name="uri.var.simplenote.name"
                     expression="fn:concat(get-property('uri.var.clio.contactFirstName'), '-', get-property('uri.var.clio.contactLastName'))" />
                  <!-- Create the contact Tag in SimpleNote -->
                  <simplenote.init>
                     <apiUrl>{$ctx:uri.var.simplenote.apiUrl}</apiUrl>
                     <authToken>{$ctx:uri.var.simplenote.authToken}</authToken>
                     <email>{$ctx:uri.var.simplenote.email}</email>
                  </simplenote.init>
                  <simplenote.createTag>
                     <name>{$ctx:uri.var.simplenote.name}</name>
                  </simplenote.createTag>
                  <sequence key="removeResponseHeaders" />
                  <!-- Retrieve the status code of the response -->
                  <property name="uri.var.simpleNoteStatusCode" expression="$axis2:HTTP_SC" />
                  <!--Checking response code to track error scenarios in SimpleNote -->
                  <switch source="get-property('uri.var.simpleNoteStatusCode')">
                     <case regex="200">
                        <property name="tags"
                           expression="fn:concat('[&quot;', get-property('uri.var.simplenote.name'), '&quot;]')" />
                        <property name="initialContent"
                           expression="fn:concat('Active note for ', get-property('uri.var.clio.contactFirstName'), ' ', get-property('uri.var.clio.contactLastName'), '...')" />
                        <!-- Create a BLANK note for the Contact. -->
                        <simplenote.init>
                           <authToken>{$ctx:simplenote.authToken}</authToken>
                           <email>{$ctx:simplenote.email}</email>
                           <apiUrl>{$ctx:simplenote.apiUrl}</apiUrl>
                        </simplenote.init>
                        <simplenote.createNote>
                           <content>{$ctx:initialContent}</content>
                           <tags>{$ctx:tags}</tags>
                        </simplenote.createNote>
                        <sequence key="removeResponseHeaders" />
                        <property name="statusCode" expression="$axis2:HTTP_SC" />
                        <!--START: Proceed to update the contact if the note was created successfully -->
                        <filter source="get-property('statusCode')" regex="200">
                           <then>
                              <property name="binaryString" expression="json-eval($.binary)" />
                              <!--Base64Decode and get the JSON object from Base64Encoded String - Issue caused by Content-Type:
                                 text/html response header. -->
                              <script language="js">
							     <![CDATA[
									function base64_decode(data) {
										var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
										var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '', tmp_arr = [];
												  
										if (data.trim().length == 0) {
										  return data;
										} else {
										  data += '';
										}
																   
										do {
      										// unpack four hexets into three octets using index points in b64
      										h1 = b64.indexOf(data.charAt(i++));
      										h2 = b64.indexOf(data.charAt(i++));
      										h3 = b64.indexOf(data.charAt(i++));
      										h4 = b64.indexOf(data.charAt(i++));
      												  
      										bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
      												  
      										o1 = bits >> 16 & 0xff;
      										o2 = bits >> 8 & 0xff;
      										o3 = bits & 0xff;
      												  
      										if (h3 == 64) {
      										tmp_arr[ac++] = String.fromCharCode(o1);
      										} else if (h4 == 64) {
      										tmp_arr[ac++] = String.fromCharCode(o1, o2);
      										} else {
      										tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
      										}
										} while (i < data.length);
												  
										dec = tmp_arr.join('');
												  
										return dec.replace(/\0+$/, '');
									}
																 
									var binaryString = mc.getProperty('binaryString');
																 
									if(binaryString != null && binaryString != ""){
      									var jsonString = base64_decode(binaryString);
      									var responseObject = eval("(" + jsonString + ")");
      									mc.setPayloadJSON(responseObject);
									}			   
									]]>
                              </script>
                              <property name="noteKey" expression="//key/text()" />
                              <!--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.simpleNoteCustomFieldName}" />
                              </call-template>
                              <property name="customFieldValues"
                                 expression="fn:concat('[{&quot;custom_field&quot;:{&quot;id&quot;:', get-property('clio.customFieldId'),'},&quot;value&quot;:&quot;', get-property('noteKey'),'&quot;}]')" />
                              <!-- Update the custom field of the contact in Clio -->
                              <clio.init>
                                 <apiUrl>{$ctx:clio.apiUrl}</apiUrl>
                                 <accessToken>{$ctx:clio.accessToken}</accessToken>
                              </clio.init>
                              <clio.updateContact>
                                 <contactId>{$ctx:uri.var.clio.contactId}</contactId>
                                 <customFieldValues>{$ctx:customFieldValues}</customFieldValues>
                              </clio.updateContact>
                              <sequence key="removeResponseHeaders" />
                              <property name="clio.contactId" expression="json-eval($.contact.id)" />
                              <!-- START: Inform the user only if the update fails. -->
                              <filter source="boolean(get-property('clio.contactId'))" regex="false">
                                 <then>
                                    <property name="id"
                                       expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'))" />
                                    <property name="errorResponse" expression="json-eval($)" />
                                    <!--Call the Response Handler Template -->
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="clio_updateContactIdWithNoteKey" />
                                       <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>
                              </filter>
                              <!-- END: Inform the user only if the update fails. -->
                           </then>
                           <else>
                              <!--Call the Response Handler Template -->
                              <call-template target="responseHandlerTemplate">
                                 <with-param name="activity" value="simplenote_createNewNote" />
                                 <with-param name="id" value="{$ctx:id.empty}" />
                                 <with-param name="status" value="{$ctx:status.failure}" />
                                 <with-param name="message" value="{ctx:message.simplenoteNoteFailed}" />
                              </call-template>
                           </else>
                        </filter>
                        <!--END: Proceed to update the contact if the note was created successfully -->
                        <property name="status" expression="get-property('status.success')" />
                        <property name="id"
                           expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'), ',simplenote_tagName:', get-property('uri.var.simplenote.name'))" />
                        <property name="message" expression="get-property('message.tagCreated')" />
                     </case>
                     <case regex="400">
                        <property name="status" expression="get-property('status.failure')" />
                        <property name="id" expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'))" />
                        <property name="message" expression="get-property('message.simplenoteBadRequest')" />
                     </case>
                     <case regex="401">
                        <property name="status" expression="get-property('status.failure')" />
                        <property name="id" expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'))" />
                        <property name="message" expression="get-property('message.simplenoteUnauthorized')" />
                     </case>
                     <default>
                        <property name="status" expression="get-property('status.failure')" />
                        <property name="id" expression="fn:concat('clio_contactId:', get-property('uri.var.clio.contactId'))" />
                        <property name="message" expression="get-property('message.simplenoteUnknownErrors')" />
                     </default>
                  </switch>
                  <!-- END of switch statement to check status codes -->
                  <!--Call the responseHandler template -->
                  <call-template target="responseHandlerTemplate">
                     <with-param name="id" value="{$ctx:id}" />
                     <with-param name="activity" value="simplenote_createTag" />
                     <with-param name="status" value="{$ctx:status}" />
                     <with-param name="message" value="{$ctx:message}" />
                  </call-template>
               </else>
            </filter>
            <!--END of filter: Checking the successful creation of the contact in Clio -->
         </else>
      </filter>
      <!--END of filter: Checking the existence of the contact in Clio -->
   </sequence>
</template>


Sample proxy for creating contacts either directly in Clio API or by retrieving selected contacts (that need legal assistance) from the Zoho CRM API
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="clio_createContactAndTag" transports="https,http" statistics="disable"
   trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
		 <sequence key="scenarioConstants" />
		 
         <!-- ZohoCrm Properties -->
         <property name="zohocrm.apiUrl" expression="json-eval($.zohoCrmApiUrl)" />
         <property name="zohocrm.accessToken" expression="json-eval($.zohoCrmAccessToken)" />
         <property name="zohocrm.contactIds" expression="json-eval($.zohoCrmContactIds)" />
         <!-- Clio Properties -->
         <property name="clio.apiUrl" expression="json-eval($.clioApiUrl)" />
         <property name="clio.accessToken" expression="json-eval($.clioAccessToken)" />
         <property name="clio.addresses" expression="json-eval($.clioContact.addresses)" />
         <property name="clio.instantMessengers" expression="json-eval($.clioContact.instantMessengers)" />
         <property name="clio.firstName" expression="json-eval($.clioContact.firstName)" />
         <property name="clio.lastName" expression="json-eval($.clioContact.lastName)" />
         <property name="clio.title" expression="json-eval($.clioContact.title)" />
         <property name="clio.prefix" expression="json-eval($.clioContact.prefix)" />
         <property name="clio.phoneNumbers" expression="json-eval($.clioContact.phoneNumbers)" />
         <property name="clio.emailAddresses" expression="json-eval($.clioContact.emailAddresses)" />
         <!-- SimpleNote properties -->
         <property name="simplenote.authToken" expression="json-eval($.simpleNoteAuthToken)" />
         <property name="simplenote.email" expression="json-eval($.simpleNoteEmail)" />
         <property name="simplenote.apiUrl" expression="json-eval($.simpleNoteApiUrl)" />
         <!--Getting the count of the zohoCrm contactIds the user has passed -->
         <property name="contactIdsCount" expression="count(//jsonObject/zohoCrmContactIds)" scope="operation" />
         <property name="contactIdIndex" expression="0" scope="operation" />
         <!--START: Priority 1 - If the user sends an array of zohoCrmContactIds then retrieve those contacts to create them 
            in Clio -->
         <filter source="get-property('operation', 'contactIdsCount')" regex="0.0">
            <!-- If zohoCrmContactIds count is zero then check whether the user has given required details to create the 
               Contact
               directly in Clio -->
            <then>
               <!--START: Priority 2 - If the user sends clioContact object then create the contact in Clio. To create the 
                  it is
                  mandatory for the user to provide firstName and lastName. -->
               <filter xpath="boolean(get-property('clio.firstName')) and boolean(get-property('clio.lastName'))">
                  <then>
                     <!-- call createContactInClioAndTagInSimpleNote template to create the contact in Clio and create the
                        tag in SimpleNote. -->
                     <call-template target="createContactAndTag">
                        <with-param name="clio.apiUrl" value="{$ctx:clio.apiUrl}" />
                        <with-param name="clio.accessToken" value="{$ctx:clio.accessToken}" />
                        <with-param name="clio.addresses" value="{$ctx:clio.addresses}" />
                        <with-param name="clio.instantMessengers" value="{$ctx:clio.instantMessengers}" />
                        <with-param name="clio.firstName" value="{$ctx:clio.firstName}" />
                        <with-param name="clio.lastName" value="{$ctx:clio.lastName}" />
                        <with-param name="clio.title" value="{$ctx:clio.title}" />
                        <with-param name="clio.prefix" value="{$ctx:clio.prefix}" />
                        <with-param name="clio.phoneNumbers" value="{$ctx:clio.phoneNumbers}" />
                        <with-param name="clio.emailAddresses" value="{$ctx:clio.emailAddresses}" />
                        <with-param name="zohocrm.isContactFromZohoCrm" value="false" />
                        <with-param name="simplenote.apiUrl" value="{$ctx:simplenote.apiUrl}" />
                        <with-param name="simplenote.authToken" value="{$ctx:simplenote.authToken}" />
                        <with-param name="simplenote.email" value="{$ctx:simplenote.email}" />
                     </call-template>
                     <loopback />
                  </then>
                  <else>
                     <!--If user doesn't send firstName and lastName of the contact, send an error message and loopback -->
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="clio_createContact" />
                        <with-param name="id" value="{$ctx:id.empty}" />
                        <with-param name="status" value="{$ctx:status.skipped}" />
                        <with-param name="message" value="{$ctx:message.insufficientContactDetails}" />
                     </call-template>
                     <loopback />
                  </else>
               </filter>
               <!-- END: Priority 2 - If the user sends clioContact object then create the contact in Clio. To create the 
                  it is
                  mandatory for the user to provide firstName and lastName. -->
            </then>
            <else>
               <!--START LOOP: Retrieve contact details of each contact Id array and create contact for each in Clio -->
               <iterate continueParent="true" id="contactsIdIterator" preservePayload="true" expression="//zohoCrmContactIds"
                  sequential="true">
                  <target>
                     <sequence>
                        <!-- Retrieving one contact at a time from the zohoCrmContactIds array -->
                        <property name="zohoCrmContactId" expression="//zohoCrmContactIds" />
                        <!--Get the contact from ZohoCRM -->
                        <zohocrm.init>
                           <apiUrl>{$ctx:zohocrm.apiUrl}</apiUrl>
                           <accessToken>{$ctx:zohocrm.accessToken}</accessToken>
                           <scope>crmapi</scope>
                        </zohocrm.init>
                        <zohocrm.getRecordsById>
                           <id>{$ctx:zohoCrmContactId}</id>
                           <moduleType>Contacts</moduleType>
                        </zohocrm.getRecordsById>
                        <sequence key="removeResponseHeaders" />
                        <property name="uri.var.zohoCrm.responseContactId" expression="json-eval($.response.result.Contacts.row.FL[0].content)" />
                        <!--START: Proceed to create the contact in Clio only if the contact was successfully retrieved from
                           ZohoCRM -->
                        <filter source="boolean(get-property('uri.var.zohoCrm.responseContactId'))" regex="false">
                           <then>
                              <property name="id"
                                 expression="fn:concat('zohoCrm_contactId : ',get-property('zohoCrmContactId'))" />
                              <property name="errorResponse" expression="json-eval($)" />
                              <!--Call the responseHandler template -->
                              <call-template target="responseHandlerTemplate">
                                 <with-param name="activity" value="zohocrm_getRecordsById" />
                                 <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="contactAttributes" expression="json-eval($.response.result.Contacts.row.FL)" />
                              <!-- Script Mediator is used to extract necessary properties from the JSON response. Attributes
                                 of the contact are returned as a map (key-value pairs) rather than as an object -->
                              <script language="js">
                                 var jsn = eval("(" + mc.getProperty("contactAttributes") + ")");
                                 for (var i = 0; i &lt; jsn.length ; i++) {
                                    if(jsn[i].val == "First Name"){
                                       mc.setProperty('firstName', jsn[i].content);
                                    } else if(jsn[i].val == "Last Name"){
                                       mc.setProperty('lastName', jsn[i].content);
                                    }else if(jsn[i].val == "Title"){
                                       mc.setProperty('title', jsn[i].content);
                                    }else if(jsn[i].val == "Salutation"){
                                       mc.setProperty('prefix', jsn[i].content);
                                    }else if(jsn[i].val == "Mailing Street"){
                                       mc.setProperty('mailingStreet', jsn[i].content);
                                    }else if(jsn[i].val == "Mailing City"){
                                       mc.setProperty('mailingCity', jsn[i].content);
                                    }else if(jsn[i].val == "Mailing State"){
                                       mc.setProperty('mailingState', jsn[i].content);
                                    }else if(jsn[i].val == "Mailing Zip"){
                                       mc.setProperty('mailingZip', jsn[i].content);
                                    }else if(jsn[i].val == "Mailing Country"){
                                       mc.setProperty('mailingCountry', jsn[i].content);
                                    }else if(jsn[i].val == "Skype ID"){
                                       mc.setProperty('skypeId', jsn[i].content);
                                    }else if(jsn[i].val == "Mobile"){
                                       mc.setProperty('phoneMobile', jsn[i].content);
                                    }else if(jsn[i].val == "Home Phone"){
                                       mc.setProperty('phoneHome', jsn[i].content);
                                    }else if(jsn[i].val == "Email"){
                                       mc.setProperty('email', jsn[i].content);
                                    }else if(jsn[i].val == "Clio Contact ID"){
                                       mc.setProperty('clioContactId', jsn[i].content);
                                    }
                                 }
                              </script>
                              <!--Constructing the complex data in Clio such as addresses,emailAddress and instantMessengers -->
                              <property name="zohocrm.addresses"
                                 expression="fn:concat('[ { &quot;street&quot;: &quot;', get-property('mailingStreet') ,'&quot;, &quot;city&quot;: &quot;', get-property('mailingCity'),'&quot;, &quot;postal_code&quot;: &quot;',get-property('mailingZip'),'&quot;, &quot;province&quot;: &quot;',get-property('mailingState'),'&quot;, &quot;country&quot;: &quot;',get-property('mailingCountry'),'&quot;}]')" />
                              <property name="zohocrm.emailAddresses"
                                 expression="fn:concat('[ { &quot;name&quot;: &quot;Work&quot;, &quot;address&quot;: &quot;',get-property('email'),'&quot;, &quot;default_email&quot;: &quot;',get-property('email') ,'&quot; } ]')" />
                              <property name="zohocrm.instantMessengers"
                                 expression="fn:concat('[ { &quot;name&quot;: &quot;Skype&quot;, &quot;address&quot;: &quot;',get-property('skypeId'),'&quot;}]')" />
                              <property name="zohocrm.phoneNumbers"
                                 expression="fn:concat('[ { &quot;name&quot;: &quot;Work&quot;, &quot;number&quot;: &quot;',get-property('phoneHome'),'&quot;}]')" />
                              <!-- Call createContactAndTag template to create the contact in Clio and
                                 create the tag in SimpleNote. -->
                              <call-template target="createContactAndTag">
                                 <with-param name="clio.apiUrl" value="{$ctx:clio.apiUrl}" />
                                 <with-param name="clio.accessToken" value="{$ctx:clio.accessToken}" />
                                 <with-param name="clio.contactType" value="Person" />
                                 <with-param name="clio.addresses" value="{$ctx:zohocrm.addresses}" />
                                 <with-param name="clio.instantMessengers" value="{$ctx:zohocrm.instantMessengers}" />
                                 <with-param name="clio.firstName" value="{$ctx:firstName}" />
                                 <with-param name="clio.lastName" value="{$ctx:lastName}" />
                                 <with-param name="clio.title" value="{$ctx:title}" />
                                 <with-param name="clio.prefix" value="{$ctx:prefix}" />
                                 <with-param name="clio.phoneNumbers" value="{$ctx:zohocrm.phoneNumbers}" />
                                 <with-param name="clio.emailAddresses" value="{$ctx:zohocrm.emailAddresses}" />
                                 <with-param name="zohocrm.apiUrl" value="{$ctx:zohocrm.apiUrl}" />
                                 <with-param name="zohocrm.accessToken" value="{$ctx:zohocrm.accessToken}" />
                                 <with-param name="zohocrm.id" value="{$ctx:zohoCrmContactId}" />
                                 <with-param name="zohocrm.clioContactId" value="{$ctx:clioContactId}" />
                                 <with-param name="zohocrm.isContactFromZohoCrm" value="true" />
                                 <with-param name="simplenote.apiUrl" value="{$ctx:simplenote.apiUrl}" />
                                 <with-param name="simplenote.authToken" value="{$ctx:simplenote.authToken}" />
                                 <with-param name="simplenote.email" value="{$ctx:simplenote.email}" />
                              </call-template>
                           </else>
                        </filter>
                        <!--END: Proceed to create the contact in Clio only if the contact was successfully retrieved from
                           ZohoCRM -->
                        <!--Increment the contactId count -->
                        <property name="contactIdIndex" expression="get-property('operation', 'contactIdIndex') + 1"
                           scope="operation" />
                     </sequence>
                  </target>
               </iterate>
               <!--END LOOP: Retrieve contact details of each contact Id array and create contact for each in Clio -->
               <!--FOR EACH Contact : END -->
               <filter xpath="get-property('operation', 'contactIdsCount') = get-property('operation', 'contactIdIndex')">
                  <then>
                     <loopback />
                  </then>
               </filter>
            </else>
         </filter>
         <!-- END: Priority 1 - If the user sends an array of zohoCrmContactIds then retrieve those contacts to create them 
            in Clio -->
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>{
               "Response":{
                  "process":"clio_matterInitiationCreateContacts",
                  "activityResponse": [$1]
                  }
               }
            </format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
   <description />
</proxy>                       


Sample request for creating contacts either directly in Clio API or by retrieving selected contacts (that need legal assistance) from the Zoho CRM API
{
	"zohoCrmApiUrl":"https://crm.zoho.com",
	"zohoCrmAccessToken":"8ada08a07f67c3da81a51838415519e9",
	"zohoCrmContactIds":[
		"1399217000000090005",
		"1399217000000083154",
		"1399217000000083049"
		],	
	"clioApiUrl":"https://app.goclio.com",
	"clioAccessToken":"fL9aZC3k6wprSqVtlfuowat1JMXX9WazGyQCkQzG",
	"clioContact":{
				"prefix": "Mr",
				"firstName": "Dilruk",
				"lastName": "Gayan",
				"title": "Project Manager",
				"addresses": [
					{
						"name": "Billing",
						"street": "456 Usman Road",
						"city": "Wellamulla",
						"postal_code": "00700",
						"country": "Sri Lanka"
					}
				],
				"emailAddresses": [
					{
						"name": "Work",
						"address": "saram@virtusa.com",
						"default_email": true
					}
				]
			},	
	"simpleNoteApiUrl":"https://simple-note.appspot.com",
	"simpleNoteAuthToken":"B2019C86386A49B2DF68EB8C025A46D65DBB255ED6BD1CDC13C9D1F4D241F97E",
	"simpleNoteEmail":"courtycorporation@gmail.com"	
}

Creating matter

  1. Add contact’s legal matter  in the active note of the contact , which is an offline process.

  2. Retrieve the contact from the Clio API using the getContact operation.
  3. Update the contact in the Clio API using the updateContact operation.
  4. Retrieve the details of the note frmo the Simplenote API using the getNote operation.
  5. To proceed with the legal case, tag the active note as "Selected" in the Simplenote API using the updateNote operation.
  6. Create the selected note as a matter in the Clio API using the createMatter operation. (A tag named as "Selected-Notes" should be created in Simplenote offline. This tag will be used to tag notes as selected.)
  7. Create a new note in the Simplenote API using the createNote operation and make it the active note for the contact.
Clio operations
Simplenote operations
Samples
Sample proxy for retrieving the contents of selected notes in Simplenote and creating them as matters in Clio under the contact identified by the name of the tag to which the note belongs
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="clio_selectNoteAndCreateMatter" transports="https,http"
   statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <sequence key="scenarioConstants" />
         <!-- Freshdesk Properties -->
         <property name="simplenote.apiUrl" expression="json-eval($.simplenoteApiUrl)" />
         <property name="simplenote.authToken" expression="json-eval($.simplenoteAuthToken)" />
         <property name="simplenote.email" expression="json-eval($.simplenoteEmail)" />
		 
		 <!-- By default, a new note will be created unless the previous active note was left intact. This is achieved by specifying 'true' for the value. -->
         <property name="simplenote.createNewNote" value="true" />
         <!-- SurveyGizmo Properties -->
         <property name="clio.apiUrl" expression="json-eval($.clioApiUrl)" />
         <property name="clio.accessToken" expression="json-eval($.clioAccessToken)" />
         <!-- Operation scoped properties -->
         <property name="responseString" value="" scope="operation" />
         <property name="activityName" value="clio_selectNoteAndCreateMatter" scope="operation" />
         <property name="noOfContacts" expression="count(//jsonObject/clioContacts)" scope="operation" />
         <property name="contactIndex" expression="0" scope="operation" />
         <!--START: Proceed with the scenario only if at least one Clio contactID is provided. -->
         <filter source="get-property('operation', 'noOfContacts')" regex="0.0">
            <then>
               <payloadFactory media-type="json">
                  <format>{
                     "Response":{
						 "activity":"clio_selectNoteAndCreateMatter",
						 "activityResponse":"clioContacts array is empty - No entries to process."
						 }
                     }
                  </format>
               </payloadFactory>
               <respond />
            </then>
            <else>
               <!--FOR EACH Clio Contact ID given in the Array: BEGIN -->
               <iterate continueParent="false" id="noteKeys" expression="//jsonObject/clioContacts" sequential="true">
                  <target>
                     <sequence>
                        <property name="clio.contactId" expression="//clioContacts/clioContactID/text()" />
                        <property name="clio.createMatter" expression="//clioContacts/createMatter/text()" />
                        <property name="id" expression="fn:concat('clio_contactId:', get-property('clio.contactId'))" />
                        <!-- Get the Contact from Clio -->
                        <clio.init>
                           <apiUrl>{$ctx:clio.apiUrl}</apiUrl>
                           <accessToken>{$ctx:clio.accessToken}</accessToken>
                        </clio.init>
                        <clio.getContact>
                           <contactId>{$ctx:clio.contactId}</contactId>
                        </clio.getContact>
                        <sequence key="removeResponseHeaders" />
                        <property name="clio.contactId" expression="json-eval($.contact.id)" />
                        <property name="clio.contactFirstName" expression="json-eval($.contact.first_name)" />
                        <property name="clio.contactLastName" expression="json-eval($.contact.last_name)" />
                        <!-- START: Create the note as matter only if the user has specified 'createMatter=true'. -->
                        <filter source="fn:lower-case(get-property('clio.createMatter'))" regex="true">
                           <then>
                              <!-- START: Create the note as matter only if the contact exists. -->
                              <filter source="boolean(get-property('clio.contactId'))" regex="true">
                                 <then>
                                    <property name="clio.customFieldArray" expression="json-eval($.contact.custom_field_values)" />
                                    <!--START: Proceed with extracting the note key from the contact details only if 'custom_field_values'
                                       are present in the response. Custom fields are not returned if the contact doesn't
                                       have a non-empty value for it. -->
                                    <filter source="boolean(get-property('clio.customFieldArray'))" regex="false">
                                       <then>
                                          <!--Call the Response Handler Template -->
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="clio_getCustomFieldArray" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status.failure}" />
                                             <with-param name="message" value="{$ctx:message.clio.noCustomFieldsFound}" />
                                          </call-template>
                                       </then>
                                       <else>
                                          <!-- 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 simpleNoteCustomFieldName = mc.getProperty('clio.simpleNoteCustomFieldName');
														 for(var i=0; i<customFieldArray.length; i++){
															if(customFieldArray[i].custom_field.name.toLowerCase() == simpleNoteCustomFieldName.toLowerCase()){
																mc.setProperty('simplenote.noteKey', customFieldArray[i].value);
																break;
															}
														 }												   
													  ]]>
                                          </script>
                                          <!--START: Proceed to create the matter only if the SimpleNote note key is found
                                             on the contact. -->
                                          <filter source="boolean(get-property('simplenote.noteKey'))" regex="false">
                                             <then>
                                                <!--Call the Response Handler Template -->
                                                <call-template target="responseHandlerTemplate">
                                                   <with-param name="activity" value="clio_getCustomFieldValue" />
                                                   <with-param name="id" value="{$ctx:id}" />
                                                   <with-param name="status" value="Failure" />
                                                   <with-param name="message"
                                                      value="{$ctx:message.clio.requiredCustomFieldNotFound}" />
                                                </call-template>
                                             </then>
                                             <else>
                                                <!-- Get the Note from SimpleNote. -->
                                                <simplenote.init>
                                                   <authToken>{$ctx:simplenote.authToken}</authToken>
                                                   <email>{$ctx:simplenote.email}</email>
                                                   <apiUrl>{$ctx:simplenote.apiUrl}</apiUrl>
                                                </simplenote.init>
                                                <simplenote.getNote>
                                                   <noteKey>{$ctx:simplenote.noteKey}</noteKey>
                                                </simplenote.getNote>
                                                <sequence key="removeResponseHeaders" />
                                                <property name="binaryString" expression="json-eval($.binary)" />
                                                <!--Base64Decode and get the JSON object from Base64Encoded String - Issue
                                                   caused by Content-Type: text/html response header. -->
                                                <script language="js">
															  <![CDATA[
																 function base64_decode(data) {
																   var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
																   var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '', tmp_arr = [];
												  
																   if (data.trim().length == 0) {
																	return data;
																   } else {
																	data += '';
																   }
																   
																   do {
																	// unpack four hexets into three octets using index points in b64
																	h1 = b64.indexOf(data.charAt(i++));
																	h2 = b64.indexOf(data.charAt(i++));
																	h3 = b64.indexOf(data.charAt(i++));
																	h4 = b64.indexOf(data.charAt(i++));
												  
																	bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
												  
																	o1 = bits >> 16 & 0xff;
																	o2 = bits >> 8 & 0xff;
																	o3 = bits & 0xff;
												  
																	if (h3 == 64) {
																	  tmp_arr[ac++] = String.fromCharCode(o1);
																	} else if (h4 == 64) {
																	  tmp_arr[ac++] = String.fromCharCode(o1, o2);
																	} else {
																	  tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
																	}
																   } while (i < data.length);
												  
																   dec = tmp_arr.join('');
												  
																   return dec.replace(/\0+$/, '');
																 }
																 
																 var binaryString = mc.getProperty('binaryString');
																 
																 if(binaryString != null && binaryString != ""){
																	var jsonString = base64_decode(binaryString);
																	var responseObject = eval("(" + jsonString + ")");
																	mc.setProperty('noteContent', responseObject.content);
																	mc.setProperty('tagName', responseObject.tags[0]);
																 }
														   
															  ]]>
                                                </script>
                                                <property name="initialContent"
                                                   expression="fn:concat('Active note for ', get-property('clio.contactFirstName'), ' ', get-property('clio.contactLastName'), '...')" />
                                                <!--START: Proceed to create the Matter only if the note is not empty. -->
                                                <filter
                                                   xpath="fn:lower-case(get-property('noteContent')) = fn:lower-case(get-property('initialContent'))">
                                                   <then>
                                                      <property name="simplenote.createNewNote" value="false" />
                                                      <property name="id"
                                                         expression="fn:concat('simplenote_notKey:', get-property('simplenote.noteKey'), ',clio_contactId:', get-property('clio.contactId'))" />
                                                      <!--Call the Response Handler Template -->
                                                      <call-template target="responseHandlerTemplate">
                                                         <with-param name="activity" value="simplenote_getNoteContent" />
                                                         <with-param name="id" value="{$ctx:id}" />
                                                         <with-param name="status" value="{$ctx:status.skipped}" />
                                                         <with-param name="message"
                                                            value="{$ctx:message.clio.caseInformationNotAdded}" />
                                                      </call-template>
                                                   </then>
                                                   <else>
                                                      <property name="openDate"
                                                         expression="get-property('SYSTEM_DATE', 'yyyy-MM-dd')" />
                                                      <!--Create the Matter with the contents of the Note. -->
                                                      <clio.init>
                                                         <apiUrl>{$ctx:clio.apiUrl}</apiUrl>
                                                         <accessToken>{$ctx:clio.accessToken}</accessToken>
                                                      </clio.init>
                                                      <clio.createMatter>
                                                         <clientId>{$ctx:clio.contactId}</clientId>
                                                         <status>Open</status>
                                                         <description>{$ctx:noteContent}</description>
                                                         <openDate>{$ctx:openDate}</openDate>
                                                         <billable>true</billable>
                                                      </clio.createMatter>
                                                      <sequence key="removeResponseHeaders" />
                                                      <property name="clioMatterId" expression="json-eval($.matter.id)" />
                                                      <!--START: Proceed to add the Note to 'Selected-Notes' tag only if
                                                         the matter was created successfully. -->
                                                      <filter source="boolean(get-property('clioMatterId'))"
                                                         regex="false">
                                                         <then>
                                                            <property name="id"
                                                               expression="fn:concat('clio_contactId:', get-property('clio.contactId'))" />
                                                            <property name="errorResponse" expression="json-eval($)" />
                                                            <!--Call the Response Handler Template -->
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="activity" value="clio_createMatter" />
                                                               <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="tags"
                                                               expression="fn:concat('[&quot;', get-property('tagName'), '&quot;,&quot;Selected-Notes&quot;]')" />
                                                            <!-- Update the Note to 'Selected-Notes' -->
                                                            <simplenote.init>
                                                               <authToken>{$ctx:simplenote.authToken}</authToken>
                                                               <email>{$ctx:simplenote.email}</email>
                                                               <apiUrl>{$ctx:simplenote.apiUrl}</apiUrl>
                                                            </simplenote.init>
                                                            <simplenote.updateNote>
                                                               <content>{$ctx:noteContent}</content>
                                                               <tags>{$ctx:tags}</tags>
                                                               <noteKey>{$ctx:simplenote.noteKey}</noteKey>
                                                            </simplenote.updateNote>
                                                            <sequence key="removeResponseHeaders" />
                                                            <property name="statusCode" expression="$axis2:HTTP_SC" />
                                                            <property name="id"
                                                               expression="fn:concat('clio_contactId:', get-property('clio.contactId'), ',clio_matterId:', get-property('clioMatterId'), ',simplenote_noteKey:', get-property('simplenote.noteKey'))" />
                                                            <filter source="get-property('statusCode')" regex="2[0-9][0-9]">
                                                               <then>
                                                                  <property name="status"
                                                                     expression="get-property('status.success')" />
                                                                  <property name="message"
                                                                     expression="get-property('message.clio.matterCreated')" />
                                                               </then>
                                                               <else>
                                                                  <property name="status"
                                                                     expression="get-property('status.failure')" />
                                                                  <property name="message"
                                                                     expression="get-property('message.clio.tagUpdationFailed')" />
                                                               </else>
                                                            </filter>
                                                            <!--Call the Response Handler Template -->
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="activity"
                                                                  value="clio_selectNoteAndCreateMatter" />
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="{$ctx:status}" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </else>
                                                      </filter>
                                                      <!--END: Proceed to add the Note to 'Selected-Notes' tag only if the
                                                         matter was created successfully. -->
                                                   </else>
                                                </filter>
                                                <!--END: Proceed to create the Matter only if the note is not empty. -->
                                             </else>
                                          </filter>
                                          <!--END: Proceed to create the matter only if the SimpleNote note ket is found
                                             on the contact. -->
                                       </else>
                                    </filter>
                                    <!--END: Proceed with extracting the note key from the contact details only if 'custom_field_values'
                                       are present in the response. Custom fields are not returned if the contact doesn't
                                       have a non-empty value for it. -->
                                 </then>
                              </filter>
                              <!-- END: Create the note as matter only if the contact exists. -->
                           </then>
                        </filter>
                        <!-- END: Create the note as matter only if the user has specified 'createMatter=true' -->
                        <!-- START: Create a empty note if the Contact ID is valid. -->
                        <filter source="get-property('simplenote.createNewNote')" regex="true">
                           <then>
                              <!-- Invalidate the Property to prevent ambiguity. -->
                              <property name="uri.var.content" action="remove" />
                              <property name="tags"
                                 expression="fn:concat('[&quot;', get-property('clio.contactFirstName'), '-', get-property('clio.contactLastName'), '&quot;]')" />
                              <property name="initialContent"
                                 expression="fn:concat('Active note for ', get-property('clio.contactFirstName'), ' ', get-property('clio.contactLastName'), '...')" />
                              <!-- Create a BLANK note for the Contact. -->
                              <simplenote.init>
                                 <authToken>{$ctx:simplenote.authToken}</authToken>
                                 <email>{$ctx:simplenote.email}</email>
                                 <apiUrl>{$ctx:simplenote.apiUrl}</apiUrl>
                              </simplenote.init>
                              <simplenote.createNote>
                                 <content>{$ctx:initialContent}</content>
                                 <tags>{$ctx:tags}</tags>
                              </simplenote.createNote>
                              <sequence key="removeResponseHeaders" />
                              <property name="statusCode" expression="$axis2:HTTP_SC" />
                              <!--START: Proceed to update the contact if the note was created successfully -->
                              <filter source="get-property('statusCode')" regex="200">
                                 <then>
                                    <property name="binaryString" expression="json-eval($.binary)" />
                                    <!--Base64Decode and get the JSON object from Base64Encoded String - Issue caused by
                                       Content-Type: text/html response header. -->
                                    <script language="js">
															  <![CDATA[
																 function base64_decode(data) {
																   var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
																   var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '', tmp_arr = [];
												  
																   if (data.trim().length == 0) {
																	return data;
																   } else {
																	data += '';
																   }
																   
																   do {
																	// unpack four hexets into three octets using index points in b64
																	h1 = b64.indexOf(data.charAt(i++));
																	h2 = b64.indexOf(data.charAt(i++));
																	h3 = b64.indexOf(data.charAt(i++));
																	h4 = b64.indexOf(data.charAt(i++));
												  
																	bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
												  
																	o1 = bits >> 16 & 0xff;
																	o2 = bits >> 8 & 0xff;
																	o3 = bits & 0xff;
												  
																	if (h3 == 64) {
																	  tmp_arr[ac++] = String.fromCharCode(o1);
																	} else if (h4 == 64) {
																	  tmp_arr[ac++] = String.fromCharCode(o1, o2);
																	} else {
																	  tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
																	}
																   } while (i < data.length);
												  
																   dec = tmp_arr.join('');
												  
																   return dec.replace(/\0+$/, '');
																 }
																 
																 var binaryString = mc.getProperty('binaryString');
																 
																 if(binaryString != null && binaryString != ""){
																	var jsonString = base64_decode(binaryString);
																	var responseObject = eval("(" + jsonString + ")");
																	mc.setPayloadJSON(responseObject);
																 }
														   
															  ]]>
                                    </script>
                                    <property name="noteKey" expression="//key/text()" />
                                    <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.simpleNoteCustomFieldName}" />
                                    </call-template>
                                    <property name="customFieldValues"
                                       expression="fn:concat('[{&quot;custom_field&quot;:{&quot;id&quot;:', get-property('clio.customFieldId'),'},&quot;value&quot;:&quot;', get-property('noteKey'),'&quot;}]')" />
                                    <!-- Update the custom field of the contact in Clio -->
                                    <clio.init>
                                       <apiUrl>{$ctx:clio.apiUrl}</apiUrl>
                                       <accessToken>{$ctx:clio.accessToken}</accessToken>
                                    </clio.init>
                                    <clio.updateContact>
                                       <contactId>{$ctx:clio.contactId}</contactId>
                                       <customFieldValues>{$ctx:customFieldValues}</customFieldValues>
                                    </clio.updateContact>
                                    <sequence key="removeResponseHeaders" />
                                    <property name="clio.contactId" expression="json-eval($.contact.id)" />
                                    <!-- START: Inform the user only if the update fails. -->
                                    <filter source="boolean(get-property('clio.contactId'))" regex="false">
                                       <then>
                                          <property name="errorResponse" expression="json-eval($)" />
                                          <!--Call the Response Handler Template -->
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="clio_updateContactIdWithNoteKey" />
                                             <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>
                                    </filter>
                                    <!-- END: Inform the user only if the update fails. -->
                                 </then>
                                 <else>
                                    <!--Call the Response Handler Template -->
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="simplenote_createNewNote" />
                                       <with-param name="id" value="{$ctx:id}" />
                                       <with-param name="status" value="{$ctx:status.failure}" />
                                       <with-param name="message" value="{$ctx:message.simplenoteNoteFailed}" />
                                    </call-template>
                                 </else>
                              </filter>
                              <!--END: Proceed to update the contact if the note was created successfully -->
                           </then>
                        </filter>
                        <!-- END: Create a empty note if the Contact ID is valid. -->
                        <!--Increment the Post Count -->
                        <property name="contactIndex" expression="get-property('operation','contactIndex') + 1"
                           scope="operation" />
                     </sequence>
                  </target>
               </iterate>
               <!--FOR EACH Clio Contact ID given in the Array: BEGIN -->
               <filter xpath="get-property('operation', 'contactIndex') = get-property('operation', 'noOfContacts')">
                  <then>
                     <loopback />
                  </then>
               </filter>
            </else>
         </filter>
         <!--END: Proceed with the scenario only if at least one Clio contactID is provided. -->
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{
               "Response":{
				   "activity":"clio_selectNoteAndCreateMatter",
				   "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 retrieving the contents of selected notes in Simplenote and creating them as matters in Clio under the contact identified by the name of the tag to which the note belongs
{
	"simplenoteApiUrl":"https://simple-note.appspot.com",
	"simplenoteAuthToken":"B2019C86386A49B2DF68EB8C025A46D65DBB255ED6BD1CDC13C9D1F4D241F97E",
	"simplenoteEmail":"courtycorporation@gmail.com",
	"clioContacts":[
		{"clioContactID":"889056955", "createMatter":true},
		{"clioContactID":"889056957", "createMatter":true},
		{"clioContactID":"889056953", "createMatter":true},
		{"clioContactID":"889056959", "createMatter":true}
	],
	"clioApiUrl":"https://app.goclio.com",
	"clioAccessToken":"fL9aZC3k6wprSqVtlfuowat1JMXX9WazGyQCkQzG"
}