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

Recruitment in PeopleHR

The first use case in the PeopleHR business scenario is used for recruitment. This page describes the relevant tasks and the operations you use in the PeopleHR connector and the other ESB connectors. 

Overview

The flow for recruitment is illustrated in the following diagram. The ESB connectors for ZohoRecruit, ZohoPeople, Xero, and Deputy will be used to connect to each service. 

  1. In this use case, the recruitment process is initiated. Job openings can be created in ZohoRecruit, and candidates can be added, tracked and associated with the above job openings in ZohoRecruit. This has to be carried out as an offline process in the ESB. 
  2. Hired candidates can be retrieved from the ZohoRecruit API using the getAssociatedCandidates operation. The getRecordById operation will be used to fetch the details of a candidate, and the getRecord operation will be used to retrieve the department details of the given ZohoPeople Department ID. Next, the createEmployee operation will be used to create employees in the PeopleHR API. ZohoRecruit is a recruitment software that could be easily used to track job openings and candidates. It can be easily integrated with other APIs such as PeopleHR to map hired candidates as employees. 
  3. Employees created in PeopleHR can also be created in ZohoPeople using the createRecord operation, in Deputy using the createEmployee operation, and in Xero using the postEmployees operation. In the Deputy API, OtherName, StartDate, and Gender will be added separately to the created employee by updating the newly created Deputy employee using the updateObject operation. 
Xero operations
Deputy operations
PeopleHR operations
ZohoRecruit operations
ZohoPeople operations
Samples 
Sample Template for Retrieving Candidate Details Using the Passed Candidate ID and Creating Employees in PeopleHR, ZohoPeople, Deputy, and Xero
<?xml version="1.0" encoding="UTF-8"?>
<!-- This template retrieves the ZohoRecruit candidate details using the passed candidate ID and creates employees in PeopleHR, ZohoPeople, Deputy, and Xero. -->
<template name="peoplehr-retrieveCandidatesAndCreateEmployees" xmlns="http://ws.apache.org/ns/synapse">
	<!-- Common parameters -->	
	<parameter name="candidateId" description="ZohoRecruit Candidate Identifier" />
	<parameter name="location" description="The work location of the employees being created." />
	<parameter name="department" description="The department of the employees being created." />	
	<parameter name="startDate" description="The start date for the employees being created." />	
	<!-- People HR parameters -->
	<parameter name="peopleHrApiUrl" description="The PeopleHR API URL." />
	<parameter name="peopleHrApiKey" description="The PeopleHR API Key." />
	
	<!-- ZohoRecruit parameters -->
	<parameter name="zohoRecruitApiUrl" description="The ZohoRecruit API URL." />
	<parameter name="zohoRecruitAuthToken" description="The encrypted alphanumeric string to authenticate the ZohoRecruit credentials." />
	<parameter name="zohoRecruitScope" description="The ZohoRecruit scope; specify the value as recruitapi." />
	
	<!-- ZohoPeople -->
	<parameter name="zohoPeopleApiUrl" description="The ZohoPeople URL." />
	<parameter name="zohoPeopleAuthToken" description="The ZohoPeople API Key." />	
	<parameter name="zohoPeopleDate" description="The ZohoPeople date string in the YYYY-MMM-DD format." />	
	<parameter name="zohoPeopleDepartmentId" description="The ZohoPeople department identifier." />	
	<!-- Deputy parameters -->
	<parameter name="deputyApiUrl" description="The Deputy API URL." />
	<parameter name="deputyAccessToken" description="The OAuth 2.0 access token of the respective account." />
	<parameter name="deputyCompanyId" description="The company identifier to create an employee." />
	<!-- Xero parameters -->
	<parameter name="xeroApiUrl" description="The Xero API URL." />	
	<parameter name="xeroConsumerKey" description="The Xero application's consumer secret." />
	<parameter name="xeroConsumerSecret" description="The Xero application's consumer secret." />
	<parameter name="xeroAccessToken" description="The access token for the respective account." />
	<parameter name="xeroAccessTokenSecret" description="The access token secret for the respesctive account." />
	
	<sequence>	
	
		<!-- PeopleHR properties -->
		<property name="uri.var.peopleHrApiUrl" expression="$func:peopleHrApiUrl"/>
		<property name="uri.var.peopleHrApiKey" expression="$func:peopleHrApiKey"/>
		
		<!-- ZohoRecruit properties -->
		<property name="uri.var.zohoRecruitApiUrl" expression="$func:zohoRecruitApiUrl"/>
		<property name="uri.var.zohoRecruitAuthToken" expression="$func:zohoRecruitAuthToken"/>
		<property name="uri.var.zohoRecruitScope" expression="$func:zohoRecruitScope"/>		
		<property name="uri.var.zohoRecruitResponseFormat" value="xml" />
		<property name="uri.var.zohoRecruitModule" value="Candidates" />
		
		<!-- ZohoPeople properties -->
		<property name="uri.var.zohoPeopleApiUrl" expression="$func:zohoPeopleApiUrl"/>
		<property name="uri.var.zohoPeopleAuthToken" expression="$func:zohoPeopleAuthToken"/>
		<property name="uri.var.zohoPeopleDate" expression="$func:zohoPeopleDate"/>
		<property name="uri.var.zohoPeopleDepartmentId" expression="$func:zohoPeopleDepartmentId"/>
		<property name="uri.var.zohoPeopleResponseType" value="application/json"/>
		<property name="uri.var.zohoPeopleFormLinkName" value="P_Employee"/>
			
		<!-- Deputy properties -->
		<property name="uri.var.deputyApiUrl" expression="$func:deputyApiUrl"/>
		<property name="uri.var.deputyAccessToken" expression="$func:deputyAccessToken"/>
		<property name="uri.var.deputyCompanyId" expression="$func:deputyCompanyId"/>		
	
		<!-- Xero properties -->
		<property name="uri.var.xeroApiUrl" expression="$func:xeroApiUrl"/>
		<property name="uri.var.xeroConsumerKey" expression="$func:xeroConsumerKey"/>
		<property name="uri.var.xeroConsumerSecret" expression="$func:xeroConsumerSecret"/>
		<property name="uri.var.xeroAccessToken" expression="$func:xeroAccessToken"/>
		<property name="uri.var.xeroAccessTokenSecret" expression="$func:xeroAccessTokenSecret"/>
		<!-- Common properties -->
		<property name="uri.var.location" expression="$func:location"/>
		<property name="uri.var.department" expression="$func:department"/>
		<property name="uri.var.startDate" expression="$func:startDate"/>
		
		<property name="uri.var.candidateId" expression="$func:candidateId"/>
		
		<zohorecruit.init>
			<apiUrl>{$ctx:uri.var.zohoRecruitApiUrl}</apiUrl>
			<authToken>{$ctx:uri.var.zohoRecruitAuthToken}</authToken>
			<scope>{$ctx:uri.var.zohoRecruitScope}</scope>
			<responseFormat>{$ctx:uri.var.zohoRecruitResponseFormat}</responseFormat>
		</zohorecruit.init>	
		<zohorecruit.getRecordById>
			<module>{$ctx:uri.var.zohoRecruitModule}</module>
			<id>{$ctx:uri.var.candidateId}</id>
			<selectColumns>{$ctx:selectColumns}</selectColumns>
		</zohorecruit.getRecordById>
		
		<property name="uri.var.candidateEmail" expression="//Candidates/row/FL[@val='Email ID']" />
		<property name="uri.var.candidateFirstName" expression="//Candidates/row/FL[@val='First name']/text()" />
		<property name="uri.var.candidateLastName" expression="//Candidates/row/FL[@val='Last name']/text()" />
		<property name="uri.var.candidateJobRole" expression="//Candidates/row/FL[@val='Current job title']/text()" />
		<property name="uri.var.candidateGender" expression="//Candidates/row/FL[@val='Gender']/text()" />		
		<property name="uri.var.candidateStreetAddress" expression="//Candidates/row/FL[@val='Street Address']" />
		<property name="uri.var.candidateCity" expression="//Candidates/row/FL[@val='City']/text()" />
		<property name="uri.var.candidateState" expression="//Candidates/row/FL[@val='State']/text()" />
		<property name="uri.var.candidateZip" expression="//Candidates/row/FL[@val='Zip']/text()" />
		<property name="uri.var.candidateLatitude" expression="//Candidates/row/FL[@val='Latitude']/text()" />
		<property name="uri.var.candidateLongitude" expression="//Candidates/row/FL[@val='Longitude']/text()" />
		
		<!-- Increment the last Employee ID to generate a new ID. -->
		<property name="uri.var.employeeIdentifier" expression="get-property('operation', 'uri.var.employeeIdentifier') + 1" scope="operation"/>
				
		<!-- Removes the unnecessary decimal value(.0) from the ID value.-->
		<property name="uri.var.employeeId"
			expression="fn:substring(get-property('operation', 'uri.var.employeeIdentifier'), 0, fn:string-length(get-property('operation', 'uri.var.employeeIdentifier')) - 1)" />
			
		<!-- The Candidate ID parameter to be used in responseHandlerTemplate. -->
		<property name="uri.var.id" expression="fn:concat('candidate_id:',get-property('uri.var.candidateId'))" />
		
		<!-- Include the following messageType to support PeopleHR employee creation. -->
		<property name="messageType" value="application/json" scope="axis2"/>
	
		<!-- Check the availability of the candidate email to proceed with employee creation; otherwise, returns an error.-->	
		<filter source="boolean(get-property('uri.var.candidateEmail'))" regex="false">
			<then>
				<!-- Email not found -->				
				<!-- PeopleHR Create Employee Failure Response-->
				<property name="uri.var.message" value="Failed to create the employees because the email of the candidate cannot be retrieved." />
				<call-template target="responseHandlerTemplate">
					<with-param name="activity" value="zohorecruit_getCandidateDetails" />
					<with-param name="id" value="{$ctx:uri.var.id}" />
					<with-param name="status" value="Error" />
					<with-param name="message" value="{$ctx:uri.var.message}" />
				</call-template>	
			</then>
			<else>		
				<!-- Create the employee address using ZohoRecruit details. -->
				<property name="uri.var.candidateAddress" expression="fn:concat(get-property('uri.var.candidateStreetAddress'), ', ', get-property('uri.var.candidateCity'), ', ', get-property('uri.var.candidateState'))" />
			
				<!-- PeopleHR Create Employee -->
				<peoplehr.init>
					<employeeId>{$ctx:uri.var.employeeId}</employeeId>
					<apiUrl>{$ctx:uri.var.peopleHrApiUrl}</apiUrl>
					<apiKey>{$ctx:uri.var.peopleHrApiKey}</apiKey>
				 </peoplehr.init>
				 <peoplehr.createEmployee>
					<lastName>{$ctx:uri.var.candidateLastName}</lastName>
					<email>{$ctx:uri.var.candidateEmail}</email>
					<firstName>{$ctx:uri.var.candidateFirstName}</firstName>							
					<startDate>{$ctx:uri.var.startDate}</startDate>
					<jobRole>{$ctx:uri.var.candidateJobRole}</jobRole>
					<location>{$ctx:uri.var.location}</location>
					<department>{$ctx:uri.var.department}</department>
					<gender>{$ctx:uri.var.candidateGender}</gender>
					<address>{$ctx:uri.var.candidateAddress}</address>
				 </peoplehr.createEmployee>
				 
				<!-- End PeopleHR Create Employee-->
				<property name="uri.var.isError" expression="json-eval($.isError)"/>
				
				<!-- Proceed with the rest of the employee creation calls only if the PeopleHR Employee creation is completed. -->		
				<filter source="get-property('uri.var.isError')" regex="true">				
					<then>					
						<!-- PeopleHR Create Employee Failure Response-->
						<property name="uri.var.peopleHrErrorMessage" expression="json-eval($.Message)" />
						
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="peoplehr_createEmployee" />
							<with-param name="id" value="{$ctx:uri.var.id}" />
							<with-param name="status" value="Error" />
							<with-param name="message" value="{$ctx:uri.var.peopleHrErrorMessage}" />
						</call-template>					
					
					</then>				
					<else>					
						<!-- PeopleHR Create Employee Successful Response -->
						<property name="uri.var.status" value="Success" />
						<property name="uri.var.peopleHrId" expression="fn:concat(get-property('uri.var.id'), ',employee_id:',get-property('uri.var.employeeId'))" />
						<property name="uri.var.message" value="Successfully created the employee." />
										
						<!-- Generate the PeopleHR Create Employee Response-->
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="peoplehr_createEmployee" />
							<with-param name="id" value="{$ctx:uri.var.peopleHrId}" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>
						<property name="uri.var.zohoPeopleId" expression="get-property('uri.var.id')" />
						<!-- Check the availability of the ZohoPeople auth token to proceed with the ZohoPeople employee creation.-->		
						<filter source="boolean(get-property('uri.var.zohoPeopleAuthToken'))" regex="false">
							<then>
								<property name="uri.var.status" value="Skipped" />
								<property name="uri.var.message" value="The API token has not been provided."/>
							</then>
							<else>
								<script language="js">
									<![CDATA[
										var xmlData = '<Request><Record><field name="EmployeeID">' + mc.getProperty('uri.var.employeeId') +
													  '</field><field name="FirstName">' + mc.getProperty('uri.var.candidateFirstName') + 
													  '</field><field name="LastName">' + mc.getProperty('uri.var.candidateLastName') + 
													  '</field><field name="EmailID">' + mc.getProperty('uri.var.candidateEmail') + 
													  '</field><field name="Current_Job_Description">' + mc.getProperty('uri.var.candidateJobRole') + 													  
													  '</field><field name="Department">' + mc.getProperty('uri.var.zohoPeopleDepartmentId') + 
													  '</field><field name="Work_location">' + mc.getProperty('uri.var.location') + 
													  '</field><field name="Address">' + mc.getProperty('uri.var.candidateAddress') + 													  
													  '</field><field name="Dateofjoining">' + mc.getProperty('uri.var.zohoPeopleDate') + 													  
													  '</field></Record></Request>';
													  
										mc.setProperty('uri.var.zohoPeopleXmlData', xmlData);
									]]>
								</script>
								<!-- ZohoPeople Create Employee -->
								<zohopeople.init>
									<apiUrl>{$ctx:uri.var.zohoPeopleApiUrl}</apiUrl>
									<authToken>{$ctx:uri.var.zohoPeopleAuthToken}</authToken>
									<responseType>{$ctx:uri.var.zohoPeopleResponseType}</responseType>
								</zohopeople.init>
						
								<zohopeople.createRecord>
									<xmlData>{$ctx:uri.var.zohoPeopleXmlData}</xmlData>
									<formLinkName>{$ctx:uri.var.zohoPeopleFormLinkName}</formLinkName>
								</zohopeople.createRecord>
							
								<property name="uri.var.zohoPeopleResponseMessage" expression="json-eval($[0].message)"/>
																
								<!-- Check whether an error code is NOT present. -->
								<filter source="get-property('uri.var.zohoPeopleResponseMessage')" regex="Successfully Added">
									<then>										
										<!-- ZohoPeople Create Employee Success Response -->	
										<property name="uri.var.status" value="Success" />
										<property name="uri.var.zohoPeopleId" expression="fn:concat(get-property('uri.var.id'), ',employee_id:',get-property('uri.var.employeeId'))" />
										<property name="uri.var.message" value="Successfully created the employee" />
									</then>
									<else>
										<!-- ZohoPeople provides a detailed error response with the 200 Status code. -->
										<property name="uri.var.zohoPeopleErrorMessage" expression="json-eval($[0].message)"/>
										<property name="uri.var.status" value="Error" />
										<property name="uri.var.message" expression="get-property('uri.var.zohoPeopleResponseMessage')"/>
									</else>
								</filter>					
							</else>
						</filter>						
						<!-- ZohoPeople Response Generation-->
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="zohopeople_createEmployee" />
							<with-param name="id" value="{$ctx:uri.var.zohoPeopleId}" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>						
						<!-- End ZohoPeople Employee Creation -->
						
						<property name="uri.var.deputyId" expression="get-property('uri.var.id')" />
						<!-- Check the availability of the Deputy auth token to proceed with the Deputy Employee creation. -->		
						<filter source="boolean(get-property('uri.var.deputyAccessToken'))" regex="false">
							<then>
								<property name="uri.var.status" value="Skipped" />
								<property name="uri.var.message" value="The API token has not been provided."/>
							</then>
							<else>
								<!-- Deputy Create Employee -->
								<deputy.init>
									<accessToken>{$ctx:uri.var.deputyAccessToken}</accessToken>
									<apiUrl>{$ctx:uri.var.deputyApiUrl}</apiUrl>
								</deputy.init>
								<deputy.createEmployee>
									<dateOfBirth>{$ctx:uri.var.deputyDateOfBirth}</dateOfBirth>
									<lastName>{$ctx:uri.var.candidateLastName}</lastName>
									<intCompanyId>{$ctx:uri.var.deputyCompanyId}</intCompanyId>
									<mobilePhone>{$ctx:uri.var.deputyMobilePhone}</mobilePhone>
									<email>{$ctx:uri.var.candidateEmail}</email>
									<firstName>{$ctx:uri.var.candidateFirstName}</firstName>
									<roleId>{$ctx:uri.var.deputyRoleId}</roleId>
								</deputy.createEmployee>
								<property name="uri.var.deputyCreateStatusCode" expression="$axis2:HTTP_SC"/>
								
								<!-- Checks successful employee creation to proceed with the employee's OtherName, StartDate and Gender fields update. -->
								<filter source="get-property('uri.var.deputyCreateStatusCode')" regex="200">
									<else>
										<!-- This check was included since there can be 500 internal server errors which do not provide a proper response; hence, cannot generate a valid response from responseHandlerTemplate. -->										
										<property name="uri.var.status" value="Error" />
										<property name="uri.var.message" expression="fn:concat('(', get-property('uri.var.deputyCreateStatusCode') , ') The employee with ',get-property('uri.var.candidateEmail'),' has not been created.')" />																						
									</else>
									<then>
										<property name="uri.var.deputyEmployeeId" expression="json-eval($.Id)"/>
										
										<filter source="boolean(get-property('uri.var.deputyEmployeeId'))" regex="true">
											<then>
												<property name="uri.var.objectName" value="Employee"/>
												<property name="uri.var.object" expression="fn:concat('{&quot;OtherName&quot;: &quot;', get-property('uri.var.employeeId'), '&quot;, &quot;StartDate&quot;: &quot;', get-property('uri.var.startDate'), '&quot;, &quot;Gender&quot;: &quot;', get-property('uri.var.candidateGender'), '&quot; }')"/>
												
												<deputy.init>
													<accessToken>{$ctx:uri.var.deputyAccessToken}</accessToken>
													<apiUrl>{$ctx:uri.var.deputyApiUrl}</apiUrl>
												</deputy.init>
												<deputy.updateObject>
													<objectName>{$ctx:uri.var.objectName}</objectName>
													<objectId>{$ctx:uri.var.deputyEmployeeId}</objectId>
													<object>{$ctx:uri.var.object}</object>
												</deputy.updateObject>
												
												<property name="uri.var.deputyUpdateStatusCode" expression="$axis2:HTTP_SC"/>
												
												<!-- Checks successful employee update. -->
												<filter source="get-property('uri.var.deputyUpdateStatusCode')" regex="200">	
													<then>
														<!-- Successful Employee Update -->
														<property name="uri.var.status" value="Success" />
														<property name="uri.var.deputyId" expression="fn:concat(get-property('uri.var.id'), ',employee_id:',get-property('uri.var.deputyEmployeeId'))" />
														<property name="uri.var.message" value="Successfully created the employee" />
													</then>
													<else>
														<!-- If the Employee update fails. -->
														<property name="uri.var.status" value="Error" />
														<property name="uri.var.message" expression="fn:concat( '(', get-property('uri.var.deputyUpdateStatusCode') , ') Successfully created the employee. However, the start date, Gender and OtherName Field with corresponding PeopleHR Employee ID: ',get-property('uri.var.employeeId'), ' has not created. Therefore a mapping cannot be created between Deputy and People HR Employees, Leave creation can be affected')" />																									
													</else>
												</filter>
											</then>
											<else>
												<!-- This check was included since there can be 500 internal server errors which do not provide a proper response; hence, cannot generate a valid response from responseHandlerTemplate. -->
												<property name="uri.var.status" value="Error" />
												<property name="uri.var.message" expression="fn:concat('Successfully created the employee. However, the Start Date, Gender and OtherName fields with the corresponding PeopleHR Employee ID: ',get-property('uri.var.employeeId'), ' has not been created. Therefore, a mapping cannot be created between Deputy and PeopleHR employees. Leave creation can be affected.')" />																									
											</else>
										</filter>
									</then>
								</filter>
							</else>
						</filter>
						<!-- Deputy Response Generation-->
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="deputy_createEmployee" />
							<with-param name="id" value="{$ctx:uri.var.deputyId}" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>						
						<!-- End Deputy Create Employee-->
						<property name="uri.var.xeroId" expression="get-property('uri.var.id')" />
						<!-- Check the availability of the Xero access token to proceed with the Xero employee creation.-->		
						<filter source="boolean(get-property('uri.var.xeroAccessToken'))" regex="false">
							<then>
								<property name="uri.var.status" value="Skipped" />
								<property name="uri.var.message" value="The API token has not been provided."/>
							</then>
							<else>
								<script language="js">
								<![CDATA[
									var gender = mc.getProperty('uri.var.candidateGender');
									if(gender == 'Male'){
										gender = 'M';
									} else if(gender == 'Female'){
										gender = 'F';
									}
								
									var employeeDetails = 	'<Employee><FirstName>' + 
															mc.getProperty('uri.var.candidateFirstName') + '</FirstName><LastName>' +
															mc.getProperty('uri.var.candidateLastName') + '</LastName><Email>' +
															mc.getProperty('uri.var.candidateEmail') + '</Email><HomeAddress><City>' + 
															mc.getProperty('uri.var.candidateCity') + '</City><Latitude>' +
															mc.getProperty('uri.var.candidateLatitude') + '</Latitude><Longitude>' +
															mc.getProperty('uri.var.candidateLongitude') + '</Longitude><StreetAddress>' +
															mc.getProperty('uri.var.candidateStreetAddress') + '</StreetAddress><Zip>' +
															mc.getProperty('uri.var.candidateZip') + '</Zip><State>' +
															mc.getProperty('uri.var.candidateState') + '</State></HomeAddress><JobTitle>' +
															mc.getProperty('uri.var.candidateJobRole') + '</JobTitle><StartDate>' +
															mc.getProperty('uri.var.startDate') + '</StartDate><Gender>' +
															gender + '</Gender></Employee>';
									
									mc.setProperty('uri.var.xeroEmployee', employeeDetails);
									
								]]>
								</script>
								<!-- Include the application/XML messageType to support Xero Employee creation. -->
								<property name="messageType" value="application/xml" scope="axis2"/>
								<property name="uri.var.acceptType" value="application/xml"/>
								<!-- Xero Create Employee -->
								<xero.init>
									<apiUrl>{$ctx:uri.var.xeroApiUrl}</apiUrl>
									<consumerKey>{$ctx:uri.var.xeroConsumerKey}</consumerKey>
									<consumerSecret>{$ctx:uri.var.xeroConsumerSecret}</consumerSecret>
									<accessToken>{$ctx:uri.var.xeroAccessToken}</accessToken>
									<accessTokenSecret>{$ctx:uri.var.xeroAccessTokenSecret}</accessTokenSecret>
									<acceptType>{$ctx:uri.var.acceptType}</acceptType>
								</xero.init>
								<xero.postEmployees>
									<employees>{$ctx:uri.var.xeroEmployee}</employees>
								</xero.postEmployees>
								
								<property name="uri.var.xeroStatusCode" expression="$axis2:HTTP_SC"/>
								<property name="uri.var.xeroEmployeeId" expression="//EmployeeID"/>
													
							
								<!-- Check the 200 Status code from the Xero response. -->
								<filter source="get-property('uri.var.xeroStatusCode')" regex="200">
									<then>
										<property name="uri.var.status" value="Success" />
										<property name="uri.var.xeroId" expression="fn:concat(get-property('uri.var.id'), ',employee_id:',get-property('uri.var.xeroEmployeeId'))" />
										<property name="uri.var.message" value="Successfully created the employee." />
									</then>
									<else>		
										<!-- Error Response for Xero Create Employee -->
										<filter source="get-property('uri.var.xeroStatusCode')" regex="401">
											<then>
												<property name="uri.var.status" value="Error" />
												<property name="uri.var.message" expression="fn:concat('(', get-property('uri.var.xeroStatusCode') , ') Authentication error occurred due to invalid credentials')" />												
											</then>
											<else>
												<filter source="$axis2:HTTP_SC" regex="400">
													<then>											
														<property name="uri.var.xeroErrorMessage" expression="//ValidationError/Message"/>
														<property name="uri.var.status" value="Error" />
														<property name="uri.var.message" expression="fn:concat('(', get-property('uri.var.xeroStatusCode') , ') ' , get-property('uri.var.xeroErrorMessage'))" />
													</then>
													<else>
														<!-- Error when creating Xero employee, but not received a 400 or 401 error status, e.g. 500. Note that this has to be created manually since it doesn't provide a valid JSON error. -->													
														<property name="uri.var.status" value="Error" />
														<property name="uri.var.message" expression="fn:concat('(', get-property('uri.var.xeroStatusCode') , ') Failed to create the employee.')" />										
													</else>
												</filter>
											</else>
										</filter>
									</else>
								</filter>	
							</else>
						</filter>
						<!-- Xero Response Generation-->
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="xero_createEmployee" />
							<with-param name="id" value="{$ctx:uri.var.xeroId}" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>	
						<!-- END of XeroEmployee Creation -->
					</else>
					<!-- PeopleHR Employee Creation Check-->
				</filter>			
			</else>
			<!-- End Email Check-->
		</filter>
	</sequence>
</template>                    
Sample Proxy for Initiating the Recruitment Process
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" 
	   name="peoplehr_createEmployees" 
	   transports="https,http" 
	   statistics="disable" 
	   trace="disable" 
	   startOnLoad="true">
	<target>
		<inSequence onError="faultHandlerSeq">
			<!-- Common properties -->			
			<property name="employeeIdIndex" expression="json-eval($.lastEmployeeId)"/>
			<property name="location" expression="json-eval($.location)"/>
			<property name="startDate" expression="json-eval($.startDate)"/>
			
			 <!-- ZohoRecruit properties -->
			<property name="zohoRecruitApiUrl" expression="json-eval($.zohoRecruitApiUrl)" />
			<property name="zohoRecruitAuthToken" expression="json-eval($.zohoRecruitAuthToken)" />
			<property name="zohoRecruitScope" expression="json-eval($.zohoRecruitScope)" />
			<property name="zohoRecruitJobId" expression="json-eval($.zohoRecruitJobId)" />
			<property name="zohoRecruitResponseFormat" value="xml" />
			<!-- PeopleHR properties -->
			<property name="peopleHrApiUrl" expression="json-eval($.peopleHrApiUrl)"/>
			<property name="peopleHrApiKey" expression="json-eval($.peopleHrApiKey)"/>
			
			<!-- ZohoPeople properties -->
			<property name="zohoPeopleApiUrl" expression="json-eval($.zohoPeopleApiUrl)"/>
			<property name="zohoPeopleAuthToken" expression="json-eval($.zohoPeopleAuthToken)"/>
			<property name="zohoPeopleDepartmentId" expression="json-eval($.zohoPeopleDepartmentId)"/>
			 
			<property name="deputyApiUrl" expression="json-eval($.deputyApiUrl)"/>
			<property name="deputyAccessToken" expression="json-eval($.deputyAccessToken)"/>
			<property name="deputyCompanyId" expression="json-eval($.deputyCompanyId)"/>
			<!-- Xero properties -->
			<property name="xeroConsumerKey" expression="json-eval($.xeroConsumerKey)"/>
			<property name="xeroConsumerSecret" expression="json-eval($.xeroConsumerSecret)"/>
			<property name="xeroAccessToken" expression="json-eval($.xeroAccessToken)"/>
			<property name="xeroAccessTokenSecret" expression="json-eval($.xeroAccessTokenSecret)"/>
			<property name="xeroApiUrl" expression="json-eval($.xeroApiUrl)"/>
			 
			<property name="uri.var.responseBuilder" value="" scope="operation" />
			<property name="uri.var.index" value="0" scope="operation" />
			<!-- increment the last employee index to create the new Employees -->
			<property name="uri.var.employeeIdentifier" expression="get-property('employeeIdIndex')" scope="operation"/>
			
			
			<!-- Build the date format for ZohoPeople.-->
			<script language="js">
				<![CDATA[
					var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
					
					var date = mc.getProperty('startDate');
					var dateElements = date.split("-");
					// Check whether the given startDate is in the valid format					
					if(dateElements != null && dateElements.length == 3){
						var year = dateElements[0] + '';
						var month = dateElements[1] + '';
						var date = dateElements[2] + '';
						
						// Check if the months, date and year values have proper lengths.
						// Check if the months, date and year values are integers.
						// Check the date value range for validity.
						if(dateElements.length == 3 && !isNaN(year) && !isNaN(month) && !isNaN(date) && 0 < parseInt(date) && parseInt(date) < 32 && year.length == 4 && month.length == 2 && date.length == 2 && months[parseInt(month - 1)] != undefined){
								mc.setProperty('zohoPeopleDate', dateElements[2] + '-' + months[parseInt(dateElements[1] - 1)] + '-' + dateElements[0]);
						}					
					}	
				]]>
			</script>
			
			<!-- Checks if the start date is valid; if not returns an error response to the user. -->
			<filter source="boolean(get-property('zohoPeopleDate'))" regex="false">
				<then>
						<!-- Error response -->
						<property name="uri.var.status" value="Error" />
						<property name="uri.var.message" value="Please check the startDate parameter; it should be in the YYYY-MM-DD format." />
						
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="peoplehr_createEmployees" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>
					<loopback />
				</then>
			</filter>
			<!-- End of ZohoPeople Date Valicdation -->
			<!-- ZohoPeople Department Validation -->
			<property name="responseType" value="application/json"/>
			<property name="formLinkName" value="P_Department"/>
			
			<zohopeople.init>
				<apiUrl>{$ctx:zohoPeopleApiUrl}</apiUrl>
				<authToken>{$ctx:zohoPeopleAuthToken}</authToken>
				<responseType>{$ctx:responseType}</responseType>
			</zohopeople.init>
			<zohopeople.getRecord>
				<recordId>{$ctx:zohoPeopleDepartmentId}</recordId>
				<formLinkName>{$ctx:formLinkName}</formLinkName>
			</zohopeople.getRecord>
			<property name="zohoPeopleDepartment" expression="json-eval($.response.result[0].Department Details.Department)"/>
			<!-- Check the availability of the ZohoPeople department to proceed. -->
			<filter source="boolean(get-property('zohoPeopleDepartment'))" regex="false">
				<then>
					<!-- Error response -->
					<property name="uri.var.status" value="Error" />
					<property name="uri.var.message" value="The relevant department could not be retrieved. Please recheck the 'zohoPeopleDepartmentId' parameter." />
					
					<call-template target="responseHandlerTemplate">
						<with-param name="activity" value="peoplehr_createEmployees" />
						<with-param name="status" value="{$ctx:uri.var.status}" />
						<with-param name="message" value="{$ctx:uri.var.message}" />
					</call-template>
					<loopback />
				</then>
			</filter>
			<!-- End of ZohoPeople Department Validation -->
			<zohorecruit.init>
				<apiUrl>{$ctx:zohoRecruitApiUrl}</apiUrl>
				<authToken>{$ctx:zohoRecruitAuthToken}</authToken>
				<scope>{$ctx:zohoRecruitScope}</scope>
				<responseFormat>{$ctx:zohoRecruitResponseFormat}</responseFormat>
			</zohorecruit.init>
			<zohorecruit.getAssociatedCandidates>
				<jobId>{$ctx:zohoRecruitJobId}</jobId>
			</zohorecruit.getAssociatedCandidates>
			
			<!-- Check whether the included lastEmployeeIndex is a number or not to proceed. Note that this has been added after the first call to avoid parser errors. -->			
			<filter source="get-property('employeeIdIndex') + 1" regex="NaN">
				<then>				
					<call-template target="responseHandlerTemplate">
						<with-param name="activity" value="peoplehr_getAssociatedCandidates" />
						<with-param name="status" value="Error" />
						<with-param name="message" value="The value given for the 'lastEmployeeId' parameter should be a number." />
					</call-template>
					<loopback/>
				</then>
			</filter>			
			<property name="uri.var.candidatesResponseString" expression="get-property('uri.var.responseString')" scope="operation" />
			<property name="uri.var.candidateCount" expression="count(//result/JobOpenings/row)" scope="operation" />
			
			<!-- Check if there are no candidates for the given Job ID; if not returns an error response to the user. -->
			<filter xpath="0 = get-property('operation', 'uri.var.candidateCount')">
				<then>
						<!-- Successful response -->
						<property name="uri.var.status" value="Skipped" />
						<property name="uri.var.message" value="There are no candidates available for the given Job ID." />
						
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="peoplehr_createEmployees" />
							<with-param name="status" value="{$ctx:uri.var.status}" />
							<with-param name="message" value="{$ctx:uri.var.message}" />
						</call-template>
					<property name="uri.var.responseBuilder" expression="json-eval($)" scope="operation" />
					<loopback />
				</then>
			</filter>
			
			<!-- Clear responseString to avoid it being appended multiple times. -->
			<property name="uri.var.responseString" value="" />
		
			<iterate id="candidatesIterator" expression="//result/JobOpenings/row" sequential="true" continueParent="true"
				preservePayload="true">
				<target>
					<sequence>
					<!-- Filter out only the hired candidates to be created as employees. -->
					<filter xpath="//FL[@val='STATUS']='Hired'">
						<then>
							<property name="uri.var.candidateId" expression="//FL[@val='CANDIDATEID']" />
							 
							 <call-template target="peoplehr-retrieveCandidatesAndCreateEmployees">
								<!-- The parameter values will be passed on to a sequence template. -->
								(
								<with-param name="candidateId" value="{$ctx:uri.var.candidateId}" />
								|
								<with-param name="peopleHrApiUrl" value="{$ctx:peopleHrApiUrl}" />
								|
								<with-param name="peopleHrApiKey" value="{$ctx:peopleHrApiKey}" />
								|
								<with-param name="location" value="{$ctx:location}" />
								|
								<with-param name="department" value="{$ctx:zohoPeopleDepartment}" />
								|
								<with-param name="startDate" value="{$ctx:startDate}" />
								|								
								<with-param name="zohoRecruitApiUrl" value="{$ctx:zohoRecruitApiUrl}" />
								|
								<with-param name="zohoRecruitAuthToken" value="{$ctx:zohoRecruitAuthToken}" />
								|
								<with-param name="zohoRecruitScope" value="{$ctx:zohoRecruitScope}" />
								|
								<with-param name="zohoPeopleApiUrl" value="{$ctx:zohoPeopleApiUrl}" />
								|
								<with-param name="zohoPeopleAuthToken" value="{$ctx:zohoPeopleAuthToken}" />
								|
								<with-param name="zohoPeopleDate" value="{$ctx:zohoPeopleDate}" />
								|
								<with-param name="zohoPeopleDepartmentId" value="{$ctx:zohoPeopleDepartmentId}" />
								|
								<with-param name="deputyApiUrl" value="{$ctx:deputyApiUrl}" />
								|
								<with-param name="deputyAccessToken" value="{$ctx:deputyAccessToken}" />
								|
								<with-param name="deputyCompanyId" value="{$ctx:deputyCompanyId}" />
								|
								<with-param name="xeroConsumerKey" value="{$ctx:xeroConsumerKey}" />
								|
								<with-param name="xeroConsumerSecret" value="{$ctx:xeroConsumerSecret}" />
								|
								<with-param name="xeroAccessToken" value="{$ctx:xeroAccessToken}" />
								|
								<with-param name="xeroAccessTokenSecret" value="{$ctx:xeroAccessTokenSecret}" />
								|
								<with-param name="xeroApiUrl" value="{$ctx:xeroApiUrl}" />
								|
								) *
							</call-template>				
							<!-- Appends responseString to responseBuilder. -->		
							<filter source="boolean(get-property('uri.var.responseString'))" regex="true">
								<then>
									<property name="uri.var.responseBuilder" expression="fn:concat(get-property('operation','uri.var.responseBuilder'), get-property('uri.var.responseString') , ', ')" scope="operation" />
								</then>
							</filter>
						</then>
					</filter>
					<property name="uri.var.index" expression="get-property('operation','uri.var.index') + 1" scope="operation" />
					</sequence>
				</target>
			</iterate>
				
			<filter xpath="get-property('operation', 'uri.var.index') = get-property('operation', 'uri.var.candidateCount')">
				<then>
					<!-- Remove the final comma appended inside the iterator mediator for final response generation inside the outsequence. -->
					<property name="uri.var.responseBuilder"
						expression="fn:substring(get-property('operation', 'uri.var.responseBuilder'), 0, fn:string-length(get-property('operation', 'uri.var.responseBuilder')))"
						scope="operation" />
					<loopback />
				</then>
			</filter>
			
		</inSequence>
		<outSequence>
			<property name="messageType" value="application/json" scope="axis2" />
		
			<!-- Generate the chained response of all the API calls in createLeads .-->
			 <payloadFactory media-type="json">
				<format>
					{
					"Response":{
						"activity":"peoplehr-retrieveCandidatesAndCreateEmployees",
						"activityResponse":[$1]
					}
					}
				</format>
				<args>
				   <arg evaluator="xml"
						expression="get-property('operation', 'responseString')"/>
				</args>
			 </payloadFactory>
			<send />
		</outSequence>
	</target>
	<description />
</proxy>                                               
Sample Request for Initiating the Recruitment Process
{
	"lastEmployeeId":1610,
	"location":"Colombo",
	"startDate":"2014-08-28",
	
	"zohoRecruitApiUrl" : "https://recruit.zoho.com",
	"zohoRecruitAuthToken" : "2020067195cb5f3f09f5fb43c3ba5d54",
	"zohoRecruitScope" : "recruitapi",
	"zohoRecruitJobId" : "285579000000057898",
	"peopleHrApiUrl":"https://api.peoplehr.net",
	"peopleHrApiKey":"c85c2570-0602-4930-a0c7-847c1a26550c",
	
	"zohoPeopleApiUrl":"https://people.zoho.com",
	"zohoPeopleAuthToken":"60c5d5032282b02d405896b634daa3d9",
	"zohoPeopleDepartmentId":"283922000000057069",
	
	"deputyApiUrl":"https://virasoft.as.deputy.com",
	"deputyAccessToken":"556815d55648e341aab1e07eb6496027",
	"deputyCompanyId":"1",
	
	"xeroApiUrl":"https://api.xero.com",
	"xeroConsumerKey":"QTOZOQXH5QWF5RUD98XI2RLZVYPUWT",
	"xeroConsumerSecret":"KYPLCBPH3TF8ZQO3S2K1WCRVBJVZAQ",
	"xeroAccessToken":"68ZT33DTVJRJMY8ZDB3MXZ9Y0HIHWQ",
	"xeroAccessTokenSecret":"IGZ9RFPOWLTIEWHO3PKAXHHFJRXFEV"
}