API 教學

WEMS HRM API 對接

提供企業系統串接 HRM 的基本規格、驗證方式、端點範例與測試入口。

快速開始

正式 API Base URL:

https://hrm.sun-bd.com

公開整合資訊:

GET https://hrm.sun-bd.com/api/v1/public/integration

Swagger:

https://hrm.sun-bd.com/swagger

公開頁面與教學不需要登入;HRM 業務資料 API 需要集中會員 token 或 API Key。

集中會員 API

會員登入、登出、refresh、會員權限與 JWKS 都集中在會員 API 管理。本專案不建立會員、不修改會員資料,也不自行簽發會員 token。

POST https://hrm.sun-bd.com/api/v1/member-auth/login
POST https://hrm.sun-bd.com/api/v1/member-auth/refresh
POST https://hrm.sun-bd.com/api/v1/member-auth/logout
GET  https://hrm.sun-bd.com/api/v1/member-auth/me/permissions

瀏覽器端使用 HRM 同網域代理,再由後端轉呼叫集中會員 API,避免跨網域限制。集中會員 API 教學:

https://loginapi.sun-bd.com/docs/integration/member-login-logout.html

API Key

企業後端系統可使用 HRM API Key 呼叫外部對接 API。

X-API-Key: whrm_xxxxxxxxxxxxxxxxxxxxx
  • API Key 僅用於系統對系統串接。
  • 一般使用者登入仍由集中會員 API 管理。
  • 權限不足回 403,金鑰錯誤或過期回 401。

常用端點

功能端點權限
健康檢查GET /api/health公開
整合資訊GET /api/v1/public/integration公開
員工資料GET /api/v1/employeesemployee.read
出勤資料GET /api/v1/attendanceattendance.read
請假資料GET /api/v1/leaveleave.read
薪資批次GET /api/v1/payroll-runspayroll.read
文件資料GET /api/v1/documentsdocument.read

程式範例

JavaScript

const response = await fetch("https://hrm.sun-bd.com/api/v1/employees?page=1&pageSize=20", {
  headers: { "X-API-Key": process.env.WEMS_HRM_API_KEY }
});
if (!response.ok) throw new Error(`HRM API failed: ${response.status}`);
const body = await response.json();

PowerShell

$headers = @{ "X-API-Key" = $env:WEMS_HRM_API_KEY }
Invoke-RestMethod -Method Get -Uri "https://hrm.sun-bd.com/api/v1/employees" -Headers $headers

錯誤處理

HTTP原因處理
401token 或 API Key 無效重新登入或更換有效金鑰。
403集中權限或 API Key 權限不足確認會員中心權限或 API Key scope。
429超過頻率限制依回應延後重試。
5xx服務端錯誤記錄時間、端點與 traceId 後回報。