MOM DingTalk Attendance Pull (Batch 50 Users) Tutorial: End-to-End Implementation from API to Database
What This Strategy Solves
In the private deployment of a manufacturing enterprise's MOM (Manufacturing Operations Management) system, attendance data was originally exported manually from the DingTalk admin console every day by HR staff and pasted into the production system. It was slow and error-prone. We used the Qeasy Data Integration Platform to handle this strategy: scheduled daily pulls of attendance records for a batch of employees, landing them into a MySQL business table for direct consumption by the production scheduling and labor-hour calculation modules. Each pull covers 50 users, matching the early, mid, and late shift rhythms.
Data Flow and Field Mapping
The data flow is one-way: DingTalk (attendance/list) → Qeasy Integration Platform → MySQL business table. The source is DingTalk's attendance query interface; the target is an INSERT SQL writing into hzero_platform.dingtalk_attendance.
Key field mapping:
| Business Meaning | DingTalk Source Field | Target MySQL Column | Notes |
|---|---|---|---|
| Primary Key | id | id | Unique on DingTalk side |
| Tenant | tenant_id | tenant_id | Critical for multi-tenant isolation |
| Employee | userId | user_id | Encoding mapping centrally managed |
| Attendance Group | groupId | group_id | |
| Schedule | planId | plan_id | |
| Punch Record | recordId | record_id | |
| Work Date | workDate | work_date | |
| Scheduled Time | baseCheckTime | base_check_time | |
| Actual Punch Time | userCheckTime | user_check_time | |
| Source Type | sourceType | source_type | |
| Punch Type | checkType | check_type | |
| Location Result | locationResult | location_result | |
| Time Result | timeResult | time_result |
In Qeasy, this entire mapping is maintained centrally in the "Field Mapping" node. When DingTalk fields change slightly, the downstream SQL does not need to be touched.
How to Configure on Qeasy
Three key points on the source side.
First, request body assembly: workDateFrom uses the function CONCAT(CURDATE(),' 00:00:00') to dynamically compose midnight of the current day; offset defaults to 0; limit is fixed at 50; userIdList is left empty to filter by all users; isI18n is hardcoded to false. These all go into "Request Parameters", where Qeasy computes them in real time during scheduling.
Second, pagination and loop: although a single limit=50 is usually sufficient, the production-safe approach is to add a "pagination loop" logic in Qeasy that increments offset by 50 until the response is empty, preventing data loss.
Third, idCheck is enabled, serving as the idempotency basis—the same record_id will not be inserted again when re-run.
The target side is relatively straightforward: an INSERT SQL with named placeholders (:id, :user_id, etc.), automatically bound by Qeasy according to the field mapping. tenant_id needs to be configured in Qeasy's "Constants / Context" as the basis for multi-tenant isolation.
Implementation Steps
We split this strategy into three scheduling phases.
Phase 1: Incremental Starting Point. On the first day of go-live, use "Full Trigger" to run a one-time historical backfill, pulling the past 30 days of attendance records in a single pass. Qeasy supports manual triggers plus time-window parameters; at this point, set workDateFrom to CONCAT(DATE_SUB(CURDATE(), INTERVAL 30 DAY),' 00:00:00').
Phase 2: Scheduled Pull. Source-side schedule 57 8,18,23 * * *, target-side schedule 59 8,18,23 * * *—the source runs 2 minutes earlier, leaving a buffer for network and parsing. Three pulls per day (early shift 8:57, late shift 18:57, night shift 23:57) exactly cover the tail end of each shift's punch window.
Phase 3: Exception Fallback. Attach a "Failure Retry" strategy in Qeasy: automatically retry 3 times on network jitter, and write failed runs into an alert queue that notifies the ops group.
Pitfall Recap
Pitfall 1: workDateTo had no upper bound, pulling tens of thousands of rows. DingTalk's interface defaults workDateTo to "current moment", which combined with limit=50 causes continuous pagination for hours. The safe approach is to explicitly fix workDateTo at 23:59:59 of the current day in Qeasy.
Pitfall 2: tenant_id was missed, mixing tenants in the database. This is a classic mistake—the MySQL table has a tenant_id column, but the integration flow did not pass it, breaking multi-tenant isolation after landing. Always set tenant_id as a required context during configuration.
Pitfall 3: Timezone inconsistency, punch times off by 8 hours. DingTalk returns UTC+8 timestamp strings, but some clients parse them in local time, causing user_check_time to be off by several hours after landing. The fix is to add a timezone normalization step in Qeasy's "Field Transformation" node.
Pitfall 4: Wrong idempotency key, re-runs caused duplicate inserts. Initially we used id as the idempotency key, but the same employee may have multiple record_id entries in one day, so the second scheduled run inserted the same batch again. Switching to a composite idempotency of record_id + user_id stabilized it.
Applicable and Non-Applicable Scenarios
Applicable: Private-deployed MOM systems needing automatic DingTalk-to-own-database attendance ingestion, with user counts in the low thousands and hour-level freshness requirements.
Not applicable: Tens of thousands of users with minute-level real-time requirements (DingTalk's interface itself has QPS limits, requiring an enterprise-grade push channel); or business scenarios that only need punch statistics rather than detailed records (in which case DingTalk's built-in reports are simpler).