Attendance API

Attendance check-in and check-out API

This API can be used to map the user ID of your employees. You can integrate this API with the attendance terminals in your organization to map the user ID of employees. The system will mark the attendance entry/exit for each employee every time when they swipe their ID card through the attendance terminals. It will also automatically update the attendance status in the web portal for every check-in and check-out.

Request URL

https://people.zoho.com/people/api/attendance?authtoken=<authtoken>&dateFormat=<dateFormat>&checkIn=<checkin time>&checkOut=<checkout time>&empId=<employeeId>&emailId=<emailId>&mapId=<mapId>

Request Parameters

authtokenSpecify the authentication token
dateFormatSpecify the correct date format
checkInSpecify the check-in time of an employee
checkOutSpecify the check-out time of an employee
empIdSpecify the employee ID of an employee
emailIdSpecify the email ID of an employee
mapIdSpecify the mapper ID of an employee

Note:

  • Check-in and Check-out parameters should be in dd/MM/yyyy HH:mm:ss date format.
  • Out of the 3 parameters - Emp ID, Email ID & Map ID, at least one of them must be given as an input to map the entry of an employee. Mapper ID is the unique ID of your Attendance system like Bio metric system which marks the attendance for a specific employee.

Attendance BulkImport API

This API is used to bulk import the check-in and check-out details of the employees. The system will mark the attendance entry/exit for all of the employees once their ID card is swipped through the attendance terminals.

Request URL

https://people.zoho.com/people/api/attendance/bulkImport?authtoken=<authtoken >&data=<JSONArray>;

Request parameter

authtokenSpecify the authentication token
data[{"empId":"1","checkIn":"2014-11-07 09:01:00"}, {"empId":"1","checkOut":"2014-11-07 09:01:00"}]
dateFormatyyyy-MM-dd HH:mm:ss

User Report API

This API is used to get attendance details of employees from the attendance reports page. Details that are present in the user report like over time/deviation time, total working hours etc for a particular employee and for a particular period chosen can be extracted with the help of this API. 

Request URL

https://people.zoho.com/people/api/attendance/getUserReport?authtoken=<authtoken>&sdate=<sdate>&edate=<edate>&empId=<employeeId>&emailId=<emailId>&mapId=<mapId>&dateFormat=<dateFormat>

Request parameter

authtokenSpecify the authentication token
sdateSpecify the correct start date
edateSpecify the correct end date
empIdSpecify the employee ID of an employee
emailIdSpecify the email ID of an employee
mapIdSpecify the mapper ID of an employee
dateFormat

Specify the date format for the date given. Eg: yyyy-MM-dd

This parameter is optional.

 

Note:

  • Start date and end date should be in the format that is specified in the company settings or in the date format of your choice which you have mentioned in the parameter. 
  • Out of the 3 parameters - Emp ID, Email ID & Map ID, at least one of them must be given as an input to map the entry of an employee. Mapper ID is the unique ID of your Attendance system like Bio metric system which marks the attendance for a specific employee.

 

Example - Programming language JAVA

Programming Language

  • JAVA

Prerequisite

  • JDK 1.6
  • commons-codec-1.3.jar, commons-httpclient-3.0.1.jar and commons-logging-1.1.jar files are available in the CLASSPATH

Code Snippet

Attendance check-in and check-out

import java.io.*;
import java.util.*;
import java.net.*; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
public class TestAPI
{
public static void main(String a[])
{
try
{
String authtoken = "YOUR AUTH TOKEN";
String targetURL = "https://people.zoho.com/people/api/attendance";
String paramname = "content";
PostMethod post = new PostMethod(targetURL);
post.setParameter("authtoken",authtoken);
post.setParameter("dateFormat","dd/MM/yyyy HH:mm:ss");
post.setParameter("checkIn","09/09/2013 09:30:45");
post.setParameter("checkOut","09/09/2013 18:45:13");
post.setParameter("empId","0941");
HttpClient httpclient = new HttpClient();
PrintWriter myout = null;
/*-------------------------------------- Execute the http request--------------------------------*/
try
{
long t1 = System.currentTimeMillis();
int result = httpclient.executeMethod(post);
System.out.println("HTTP Response status code: " + result);
System.out.println(">> Time taken " + (System.currentTimeMillis() - t1));
/*-------------------------------------- Execute the http request--------------------------------*/
/* ---------------------------writing the response to a file--------------------*/
myout = new PrintWriter(new File("response.xml"));
myout.print(post.getResponseBodyAsString());
/* ---------------------------writing the response to a file--------------------*/
/*-----------------------Get response as a string ----------------*/
String postResp = post.getResponseBodyAsString();
System.out.println("postResp=======>"+postResp);
/* ---------------------Get response as a string ----------------------------*/
if(postResp.equals("Invalid Ticket Id"))
{
// generate new auth token and call the API
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
myout.close();
post.releaseConnection();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Attendance bulk import

import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.json.JSONArray;
import org.json.JSONObject;
public class JavaCode { public static void main(String a[]) { try { JSONArray array = new JSONArray();
JSONObject val = new JSONObject();
val.put("empId", "1");
val.put("checkIn", "2014-11-07 09:01:00");
array.put(val);
val = new JSONObject();
val.put("empId", "1");
val.put("checkOut", "2014-11-07 09:01:00");
array.put(val);
String authtoken = "YOUR AUTHTOKEN";
String targetURL = "https://people.zoho.com/people/api/attendance/bulkImport";
String dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
PostMethod post = new PostMethod(targetURL);
post.setParameter("authtoken", authtoken);
post.setParameter("dateFormat", dateTimeFormat);
post.setParameter("data", array.toString());
HttpClient httpclient = new HttpClient();
PrintWriter myout = null; /*-------------------------------------- Execute the http request--------------------------------*/ try { long t1 = System.currentTimeMillis();
int result = httpclient.executeMethod(post);
System.out.println("HTTP Response status code: " + result);
System.out.println(">> Time taken " + (System.currentTimeMillis() - t1));
/*-------------------------------------- Execute the http request--------------------------------*/ /* ---------------------------writing the response to a file--------------------*/ myout = new PrintWriter(new File("response.xml"));
myout.print(post.getResponseBodyAsString());
/* ---------------------------writing the response to a file--------------------*/ /*-----------------------Get response as a string ----------------*/ String postResp = post.getResponseBodyAsString();
System.out.println("postResp=======>" + postResp);
/* ---------------------Get response as a string ----------------------------*/ if (postResp.equals("Invalid Ticket Id")) { // generate new auth token and call the API } } catch (Exception e) { e.printStackTrace();
} finally { myout.close();
post.releaseConnection();
} } catch (Exception e) { e.printStackTrace();
} } }

 

Example - Programming language C#

Programming Language

  • C#

Prerequisite

  • C#

Code Snippet

using System.Web;
using System..Net;
string authtoken = "YOUR AUTHTOKEN HERE";
String zohopeopleurl = "https://people.zoho.com/people/api/attendance?";
string postContent = "authtoken=" + authtoken;
postContent = postContent + "&dateFormat=dd/MM/yyyy HH:mm:ss&checkIn=02/01/2014 08:00:00&checkOut=02/01/2014 05:00:00&empId=3";
string result = AccessAPI(zohopeopleurl, postContent);
public static string AccessAPI(string url, string postcontent)
{
byte[] bodyBytes = System.Text.Encoding.UTF8.GetBytes(postcontent);
HttpWebRequest request = default(HttpWebRequest);
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "Post"; //methodtype;//-post or get
request.ContentType = "application/x-www-form-urlencoded";
using (Stream ostream = request.GetRequestStream())
{
ostream.Write(bodyBytes, 0, bodyBytes.Length);
ostream.Flush();
ostream.Close();
}
HttpWebResponse response = default(HttpWebResponse);
response = (HttpWebResponse)request.GetResponse();
StreamReader strrespo = default(StreamReader);
strrespo = new StreamReader(response.GetResponseStream());
string s = null;
s = strrespo.ReadToEnd();
return s;
}

Example - Programming language PHP#

Programming Language

  • PHP#

Prerequisite

  • PHP#

Code Snippet

$request_url = 'https://people.zoho.com/people/api/attendance'; $authToken = "YOUR AUTH TOKEN"; $dateFormat = "dd/MM/yyyy HH:mm:ss"; $checkIn = "29/10/2014 09:05:00"; $checkOut = "29/10/2014 17:30:00"; $empID = "1"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $request_param = "authtoken=" . $authToken . "&checkIn=" . $checkIn . "&checkOut=" . $checkOut . "&dateFormat=" . $dateFormat . "&empId=" . $empID; curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $response_info = curl_getinfo($ch); curl_close($ch); $response_body = substr($response, $response_info['header_size']); echo '\nRequest Parm : ' . $request_param; echo "\nResponse HTTP Status Code : "; echo $response_info['http_code']; echo "\nResponse" . $response_body; ?>

 

Attendance Entries

This API is used for getting the Employee attendance entries.

Request URL

https://people.zoho.com/people/api/attendance/getAttendanceEntries?authtoken=<authtoken>&date=<date>&dateFormat=<dateformat>&erecno=<erecno>&mapId=<mapId>&emailId=<emailId>&empId=<empId>

 

Request parameter

authtokenSpecify the authentication token
dateSpecify the date in organisation date format.(Optional)
dateFormatSpecify the date format.(Optional)
erecnoSpecify employee erecno.(Optional)
mapIdSpecify mapper id.(Optional)
emailIdSpecify employee email id.(Optional)
empIdSpecify employee id.(Optional)

Note:

  • Date parameters should be in zoho people configuration date format. If we didn't specify, it will consider current date.
  • Default date format is dd-MMM-yyyy.
  • Specify either erecno, mapId, emailId, empId for getting subordinate details. If we didn't specify, login user details will fetch.

Response Example

{
  "allowedToCheckIn": false,
  "firstIn": "2017-01-25 12:12:35.0",
  "lastOut": "2017-01-25 13:05:00.0",
  "totalHrs": "00:52",
  "status": "Present",
  "entries": [
    {
      "checkOut": "-",
      "checkIn": "25-Jan-2017 - 02:08 PM"
    },
    {
      "checkOut": "25-Jan-2017 - 01:05 PM",
      "checkIn": "25-Jan-2017 - 12:12 PM"
    }
  ]
}

Employee shift mapping API

This API is used to map employees to respective shifts. By making use of this API, you can associate an employee, with his/her employee ID to a particular shift. The employee gets mapped to shift based on the given 'From' and 'To' date specified.

Request URL

https://people.zoho.com/people/api/attendance/updateUserShift?authtoken=<authtoken>&dateFormat=<dateformat>&empId=<employee Id>&shiftName=<shift name>&fdate=<FromDate>&tdate=<toDate>

Request Parameters

AuthtokenSpecify the authentication token
empIdEmployee ID of an employee
shiftNameShift to be mapped
fdateFrom date
tdateTo date
dateFormatCorrect date format(optional)

Note: Date Format- use Date Format of organisation or specify the format

 

Getting shift details of employee API

This API is used to fetch the shift configuration details of an employee. All the details of the shift, that has been configured to the employee, in the given duration can be fetched using this API. Details include shifts mapped to the employee, start and end time of the shift and holiday, weekend set for the shift.

Request URL

https://people.zoho.com/people/api/attendance/getShiftConfiguration?authtoken=<authtoken>&dateFormat=<dateformat>&empId=<employee Id>&emailId=<email Id>&mapId=<Mapper Id>&sdate=<startDate>&edate=<endDate>

Request Parameters

mapIdMapper ID of the employee
emailIdMail ID of the employee
empIdEmployee ID of an employee
sdateStart date
edateEnd date

Note:

  • Specify either Map ID,Email ID or EmpID.
  • DateFormat- Date Format of the organisation

 

Error codes

Please refer Error codes.