考勤 API
考勤签到和签退 API
此 API 可用于映射员工的用户 ID。您可将此 API 与您机构中的考勤终端集成,以便映射员工的用户 ID。每当员工通过考勤终端刷他们的身份卡时,系统将为每位员工标记考勤签到/签退。它还将为每次签到和签退更新 Web 门户中的考勤状态。
请求 URL
https://people.zoho.com.cn/people/api/attendance?authtoken=<authtoken>&dateFormat=<dateFormat>&checkIn=<checkin time>&checkOut=<checkout time>&empId=<employeeId>&emailId=<emailId>&mapId=<mapId>
请求参数
authtoken | 指定身份验证令牌 |
dateFormat | 指定正确的日期格式 |
checkIn | 指定员工的签到时间 |
checkOut | 指定员工的签退时间 |
empId | 指定员工的员工 ID |
emailId | 指定员工的邮箱地址 |
mapId | 指定员工的映射 ID |
注:
- 签到和签退参数应为 dd/MM/yyyy HH:mm:ss 日期格式。
- 在 Emp ID、Email ID 和 Map ID 这 3 个参数中,至少必须将其中一个作为输入以映射员工的进入。映射 ID 是您的考勤系统(例如,生物指标系统)的唯一 ID,用于标记特定员工的出勤。
考勤批量导入 API
此 API 用于批量导入员工的签到和签退详情。员工通过考勤终端刷他们的身份卡之后,系统将为所有员工标记考勤签到/签退。
请求 URL
https://people.zoho.com.cn/people/api/attendance/bulkImport?authtoken=<authtoken >&data=<JSONArray>;
请求参数
authtoken | 指定身份验证令牌 |
data | [{"empId":"1","checkIn":"2014-11-07 09:01:00"}, {"empId":"1","checkOut":"2014-11-07 09:01:00"}] |
dateFormat | yyyy-MM-dd HH:mm:ss |
用户报表 API
此 API 用于从考勤报表页面获取员工的考勤详情。用户报表中包括的特定员工和所选特定期间的超过/偏差时间、总工作时数等详情可利用此 API 提取出来。
请求 URL
https://people.zoho.com.cn/people/api/attendance/getUserReport?authtoken=<authtoken>&sdate=<sdate>&edate=<edate>&empId=<employeeId>&emailId=<emailId>&mapId=<mapId>
请求参数
authtoken | 指定身份验证令牌 |
sdate | 指定正确的开始日期 |
edate | 指定正确的结束日期 |
empId | 指定员工的员工 ID |
emailId | 指定员工的邮箱地址 |
mapId | 指定员工的映射 ID |
注:
- 开始日期和结束日期应按照公司设置中指定的格式。
- 在 Emp ID、Email ID 和 Map ID 这 3 个参数中,至少必须将其中一个作为输入以映射员工的进入。映射 ID 是您的考勤系统(例如,生物指标系统)的唯一 ID,用于标记特定员工的出勤。
示例 - 编程语言 JAVA
编程语言
- JAVA
先决条件
- JDK 1.6
- CLASSPATH 中提供了 commons-codec-1.3.jar、commons-httpclient-3.0.1.jar 和 commons-logging-1.1.jar 文件
代码片断
考勤签到和签退
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.cn/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();
}
}
}
考勤批量导入
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.cn/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();
} } }
示例 - 编程语言 C#
编程语言
- C#
先决条件
- C#
代码片断
using System.Web;
using System..Net;
string authtoken = "YOUR AUTHTOKEN HERE";
String zohopeopleurl = "https://people.zoho.com.cn/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;
}
示例 - 编程语言 PHP#
编程语言
- PHP#
先决条件
- PHP#
代码片断
$request_url = 'https://people.zoho.com.cn/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; ?>
错误代码
请参阅错误代码。