Qeasy Cloud
Get Started

Syncing Feishu Approval Instances into MySQL: A Field Guide for Loan Request Forms

· Integration Solutions· 19 views· 4 min read
MySQLFeishu轻易云审批集成Field MappingIncremental Sync

What This Strategy Solves

In many organizations, employee loan requests are submitted through Feishu approvals, but the ledger, fund-occupation analysis, and payment reconciliation all live in a business database (MySQL). When approval results never reach the database, finance teams end up exporting form data manually, which is slow and error-prone. What we build here is a stable pipeline that pushes Feishu approval instances into MySQL by their serial number, turning loan requests into queryable, joinable, and reusable structured records.

Data Flow and Field Mapping

The flow is straightforward: Feishu (approval instance) → Qeasy middleware → MySQL business table. The source side uses Feishu's Open API for approval instances, while the target side writes to MySQL via a batchexecute SQL.

Key source fields (exposed as widget IDs from the approval form):

  • serial_number: approval instance number, used as the business key
  • instance_code: approval instance ID, used for idempotency
  • applicant (from a widget field): the requester
  • loan_type (from the _text-suffixed field): loan type, where the _text suffix carries the display label
  • related_unit_type: counterparty type
  • explanation_2: explanation field

Target MySQL columns:

  • serial_number — code
  • instance_code — approval id
  • applicant — requester
  • loan_type — loan type
  • related_unit_type — counterparty type
  • explanation_2 — explanation

The most common trap in mapping is option-type fields. Feishu widgets return display text in the _text variant, not the underlying enum. Storing raw text in MySQL kills downstream analytics. The robust approach is to maintain a centralized mapping table in Qeasy, translate the display label (travel / petty cash / procurement, etc.) into a business dictionary code, store the dictionary code in MySQL, and redundantly keep the label in a separate display column.

Configuring It in Qeasy

In Qeasy, we structure this strategy into three segments: source read + transformation + target write.

  1. Source platform: choose Feishu, select the /open-apis/approval/v4/instances endpoint, method GET. Bind approval_code to the loan-request form's ID. Use {{CURRENT_TIME}}000 placeholders for start_time / end_time so Qeasy fills the time window automatically based on the scheduling context, instead of maintaining it manually.
  2. Transformation layer: in Qeasy's field mapping, rename widget fields into target column names (applicant, loan_type, etc.), run the _text fields through the mapping table to produce dictionary codes, and enable idCheck using serial_number as the primary key to prevent duplicate writes.
  3. Target platform: choose MySQL, execution type SQL, write via batchexecute in batch mode. Set crontab to * * * * * for near-real-time landing on the target side.

The source crontab is intentionally set to 1 1 1 1 1 (placeholder), because the real time windows are managed by Qeasy's unified scheduler rather than embedded in the API request. This "the source only fetches, the platform orchestrates" pattern is one we have iterated on with many customers.

Implementation Steps

We recommend rolling this out in three phases rather than a big bang:

  1. Phase 1 — Full backfill. Manually trigger a full pull in Qeasy and replay historical approval instances into MySQL in time-windowed batches. The focus here is validating field mapping, dictionary codes, and character set issues (Feishu emojis and rare-character names most often expose MySQL's charset limits at this step).
  2. Phase 2 — Align the incremental starting point. Configure the incremental start timestamp in Qeasy as "last full-load end time + 1 second" and persist this value in a config table. Never use vague starts like "current time minus N minutes" — missed records are almost guaranteed otherwise.
  3. Phase 3 — Steady-state scheduling. The source pulls increments on a business-driven cadence (e.g. every minute), and the target lands via * * * * *. After one week, reconcile the total serial_number count in MySQL against Feishu's approved-instance report; the delta must be zero.

Source reads are scheduling-driven and target writes are also scheduling-driven — this is the typical "dual-track full + incremental" model: full loads for initial backfill and recovery, incremental for day-to-day.

Pitfalls From the Field

  1. Storing _text suffix fields directly. A classic mistake is writing widgetxxx_text verbatim into MySQL, which leaves loan_type as plain text and breaks enum-based aggregation. The robust approach is mapping to dictionary codes in Qeasy and redundantly storing labels in a display column.
  2. Drifting incremental start. Using {{CURRENT_TIME}} directly as the start looks fine but shifts the window every run, so approvals that were just submitted but not yet approved keep reappearing. The robust approach is filtering on approval completion time, not submission time.
  3. idCheck disabled causes duplicates. When Feishu instances are pulled multiple times, missing primary-key checks produces duplicate serial_number rows in MySQL. The robust approach is idCheck=true on the target, converting primary-key conflicts into updates rather than inserts.
  4. Time-window truncation across days. Feishu's API caps end_time; overly wide windows get truncated. The robust approach is shrinking the per-call window and slicing it by hour or day inside Qeasy.
  5. Charset and null semantics. Feishu names can contain emojis or rare characters; if MySQL is not utf8mb4, writes fail. When the requester field is empty, decide explicitly between empty string and NULL so downstream metrics stay consistent.

When to Use It — and When Not To

Use it when: Feishu approval results need to land in a business database for ledger, reporting, or reconciliation; the form fields are relatively stable; and the daily volume is manageable (under ~1,000 instances per day).

Don't use it when: the approval form's fields change frequently or widget IDs are reused; or when real-time requirements are sub-second and volumes are very high — in those cases, prefer event-driven pushes plus streaming writes instead of polling.

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/solutions/strat-mysql-feishu-1122-mysql-07a15ec0

Comments