Skip to main content

Assign Attendance Members: Batch Addition and Precise Management

Overview

Background

Organizations change constantly. Employees join, leave, transfer roles, or move between departments. Each change requires HR or an Admin to update attendance group members one by one in the DingTalk admin console. New employees must be added to an attendance group, departing employees must be removed, and transferred employees must be moved to a different attendance group. An organization with 1,000 or more employees may see dozens to hundreds of changes every month. Manual updates take significant time and effort. They also lead to omissions and mistakes, which cause clock-in errors and inaccurate attendance data.

Key Benefits

This solution automates the full lifecycle of attendance group members. It turns manual batch additions, queries, updates, and deletions into standardized, API-driven operations. The result is more efficient HR system operations and consistent data.
  • Automated batch member management: Add, query, update, and delete members through APIs with no manual intervention.
  • Precise API selection: Choose the best query API for individual, department, or mixed members to retrieve complete and accurate data.
  • Real-time verification: Check whether a user belongs to a specific attendance group, and verify results immediately after each update to keep data consistent.
  • Unified cross-system data: Sync attendance group member data in real time across your HR system, OA system, and DingTalk to eliminate data silos.

Use Cases

This solution fits the following typical business scenarios:
  • Employee onboarding: After HR enters a new employee in the HR system, add the employee to the attendance group of the corresponding department automatically.
  • Employee offboarding: After the OA resignation approval is approved, remove the employee from all attendance groups automatically.
  • Role transfers: When an employee transfers, remove the employee from the original attendance group and add them to the new department’s attendance group automatically.
  • Batch member adjustments: After an Organization Structure change, update the member lists of multiple attendance groups in batches.

Typical Business Scenarios

Scenario 1: Add New Employees to Attendance Groups Automatically

Pain Points

In the traditional process, HR must sign in to the DingTalk admin console on each new employee’s first day, find the attendance group of the corresponding department, and add each new employee manually. If 5 to 10 employees join every day, HR repeats this task many times. Omissions or wrong group selections are common, and new employees cannot clock in as expected.

Value

  • Automated flow The automated flow runs in five steps:
    1. HR enters the new Employee record (name, Department, position).
    2. Match the target attendance group by the employee’s department ID and look up its groupKey.
    3. Call the batch-add-employees API to add the new employee’s userId to the attendance group.
    4. Call the query-members-by-id API to verify that the employee was added successfully.
    5. Clock-in permission takes effect the same day and attendance recording begins.
  • Key advantages
    • Fully automatic trigger: After HR enters a new employee, the HR system calls the API to add the employee to an attendance group. No manual action is required.
    • Precise matching: The system matches the attendance group to the employee’s department automatically, which prevents wrong selections.
    • Immediate effect: The system verifies the result right after the addition, so new employees can clock in on their first day.
    • Audit trail: Each action records the operator, timestamp, and attendance group ID to meet compliance requirements.

Scenario 2: Remove Departing Employees from Attendance Groups Automatically

Pain Points

When an employee leaves, HR must manually remove the employee from every related attendance group. If the employee belongs to multiple attendance groups (for example, a primary department and a project team), manual removal is easy to miss. Departing employees may still clock in, attendance data becomes inaccurate, and payroll calculations may go wrong.

Value

  • Automated flow The automated flow runs in five steps:
    1. The OA Approval resignation request is approved, and the system captures the event to trigger the Automation.
    2. Call the queries-a-user-attendance-group API to retrieve the IDs of all attendance groups the Employee belongs to.
    3. Iterate over those groups and call the batch-delete-employees API to remove the Employee in bulk.
    4. Call the query-members-by-id API to verify, one by one, that the Employee has been removed from every attendance group.
    5. The Employee’s clock-in permission is revoked and attendance recording stops.
  • Key advantages
    • Fully automatic trigger: After the OA resignation approval is approved, the removal runs automatically with no manual intervention.
    • Full coverage: Query and remove the employee from all attendance groups in a single pass to avoid omissions.
    • Immediate effect: The system verifies the result right after removal, so departing employees can no longer clock in.
    • Complete audit logs: Every removal records detailed information to meet compliance audit and traceability requirements.

Implementation Guide

Technical Architecture

This solution is built on the Server API of the DingTalk Open Platform. The core technical components include:
  • Authentication layer: Get an access_token with your Client ID and Client Secret to secure API calls.
  • Member management layer: Provides complete API capabilities to add, query, update, and delete attendance group members in batches.
  • Smart routing layer: Selects the best query API based on member type (individual, department, or mixed) to retrieve complete data.
  • Error handling layer: A complete error code system and retry mechanism help you locate and resolve issues quickly.
API version note: The Server API has a new version and a legacy version. Use the new version first for better performance and feature support.

Prerequisites

Before you start, make sure that the following conditions are met:
  • App setup: Create and configure an Internal app. For details, see Create and Configure an App.
  • Permissions: You have DingTalk Organization Admin or Sub Admin permissions, and you have applied for the following API permissions:
    • qyapi_attendance_group_manage (attendance group management permission)
    • qyapi_attendance_group_read (attendance group read permission)
  • Development environment: A Java development environment (JDK 1.6 or later) and the Maven build tool are installed.
  • SDK: Download the DingTalk Server-side SDK. For details, see Download the Server-side SDK. The SDK supports multiple languages, including Java, Python, and Go.

Code Implementation

Step 1: Get the App credential, including the client ID and Client Secret. Step 2: Apply for the qyapi_attendance_group_manage and qyapi_attendance_group_read API permissions. Step 3: Get the Access credential. For details, see Get the access_token of an Internal App. When you call an API, the access token authenticates the caller’s identity. Step 4: Call the attendance APIs:
  1. Call the Server API Batch Add Attendance Members to add attendance members to an attendance group.
  2. Call the Server API Get a User’s Attendance Group to get information about the attendance group a user belongs to.
  3. Get attendance member information for an attendance group:
  4. Call the Server API Check Whether a User Is in the Attendance Group to check whether a department or employee belongs to an attendance group.
  5. Call the Server API Update Attendance Members to update the attendance members of an attendance group.
  6. Call the Server API Batch Delete Attendance Members to delete attendance members.

Implementation Steps

Step 1: Get the App Credential

  1. Sign in to the DingTalk Developer Console.
  2. Select the target app to open its details page.
  3. Click Basic Information > Credentials and Basic Information.
  4. Record the app’s Client ID and Client Secret.

Note

Keep your Client Secret secure and never share it with third parties. Store it in environment variables or a key management system instead of hardcoding it.

Step 2: Add API Permissions

  1. On the app details page, click Manage permissions.
  2. Enter the following permission identifiers in the permission search box and apply for them:
    • qyapi_attendance_group_manage (attendance group management permission): Create, update, and delete attendance groups.
    • qyapi_attendance_group_read (attendance group query permission): Query attendance group summaries and details.
Different business scenarios may require different permission combinations. Apply for permissions based on your actual needs. For example, batch import scenarios also require permissions for batch user operations.

Step 3: Get the Access Credential (access_token)

Use the Client ID and Client Secret from Step 1 to get the Access credential. For details, see Get the access_token of an Internal App.
Best practices:
  • Caching: An access_token is valid for 2 hours. Cache it in memory or Redis, and refresh it 5 minutes before it expires.
  • Concurrency control: Prevent conflicts caused by multiple threads refreshing the token at the same time. Use a distributed lock.
  • Retry on error: Retry automatically during network fluctuations, up to 3 times, with increasing intervals (1s → 2s → 4s).

Step 4: Call the Core APIs

  1. Batch add attendance members: Call the Server API Batch Add Attendance Members to add attendance members to an attendance group.
  2. Get a user’s attendance group: Call the Server API Get a User’s Attendance Group to get information about the attendance group a user belongs to.
  3. Get attendance member information for an attendance group The following three member query APIs differ mainly when an attendance group includes departments as attendance members. In the admin console, open Attendance > Attendance Group Management and edit an attendance group. The attendance members field can hold both a whole Department and an individual User at the same time. A separate non-attendance members field is also available. Note: ✅ means the data can be retrieved. ❎ means the data cannot be retrieved.
    • Get the user IDs of attendance members: Call the Server API Get the User IDs of Attendance Members to get the user IDs of attendance members.
    • Get attendance member information: Call the Server API Get Attendance Members to get attendance member information.
    • Query the list of attendance members (with pagination): Call the Server API Query the List of Attendance Members to get the list of attendance members.
  4. Check whether a user is in the attendance group: Call the Server API Check Whether a User Is in the Attendance Group to confirm whether an employee belongs to a specific attendance group.
  5. Update attendance members: Call the Server API Update Attendance Members to adjust the attendance group member list (add or remove employees or departments).
  6. Batch delete attendance members: Call the Server API Batch Delete Attendance Members to remove departing or transferred employees from an attendance group.
Implementation checklist:
  • ✅ All API calls return a success status code (errcode=0).
  • ✅ After each add or delete action, call the verification API to confirm the result.
  • ✅ Error logs are complete for issue tracing.
  • ✅ Attendance group member data in the HR system and DingTalk is compared regularly and stays consistent.

FAQ

  • Q1: What are the differences between the three member query APIs? A: Each API fits a different member type scenario: When an attendance group includes department members, note the following: a query by an individual user ID returns that employee’s information. A query by department ID does not return details of the employees in that department directly. Call the department member query API separately.
  • Q2: How do I handle partial failures when adding members in batches? A: The batch add API uses a “best effort” strategy and returns successful and failed members separately. Follow these steps:
    1. Parse the response to extract the user IDs of failed members and the error reasons.
    2. Log the failures and analyze the causes (for example, the user does not exist or is already in the attendance group).
    3. Retry recoverable errors (for example, a newly created user has not synced yet).
    4. Skip and log unrecoverable errors (for example, the user has already left the organization).
  • Q3: How do I make sure a departing employee is fully removed? A: Follow these steps to ensure complete removal:
    1. After the OA resignation approval is approved, call the Get a User’s Attendance Group API to get the IDs of all attendance groups the employee belongs to.
    2. Iterate over all attendance groups and call the Batch Delete Attendance Members API to remove the employee.
    3. Call the Check Whether a User Is in the Attendance Group API to confirm that the employee has been removed from all attendance groups.
    4. Log the action, including the list of attendance group IDs, the time of the action, and the operator.