數位減碳雲資料交換平台(DSCE) · 權限受控資料交換 API · 適用對象:資訊商 (ISP) 與進階使用者的系統整合開發人員
DSCE API 是疊加在 PACT Pathfinder v3 之上的權限受控層,具備多租戶資料隔離與完整審計。所有端點以
/api/dsce/為前綴。原生 v3 API 僅限特定合作廠商,另見 v3 文件。
呼叫任何 /api/dsce/* 端點前,需同時滿足:
isApiDsceEnabled = 1(已開通)。未開通一律回 403。首次使用前,需申請一組 client_id 與 client_secret。
POST/api/auth/credentials(無需任何認證標頭)
{
"client_id": "dsce-a1b2c3d4",
"client_secret": "Xy9kLmNoPqRsTuVwXy12"
}
⚠️
client_secret僅顯示一次,請立即妥善保存。
以 HTTP Basic Authentication 帶入憑證換取 Bearer Token,Token 有效期限 30 分鐘(1800 秒)。後續所有 DSCE API 動作皆須帶入此 Token。
POST/api/auth/token
| 標頭 | 值 |
|---|---|
Authorization | Basic <Base64(client_id:client_secret)> |
Content-Type | application/x-www-form-urlencoded |
| 欄位 | 值 |
|---|---|
grant_type | client_credentials(固定值) |
curl -X POST https://<host>/api/auth/token \
-u "dsce-a1b2c3d4:Xy9kLmNoPqRsTuVwXy12" \
-d "grant_type=client_credentials"
{
"access_token": "eyJhbGci...",
"expires_in": 1800,
"token_type": "Bearer",
"scope": "footprint:list profile footprint:read email"
}
後續所有 DSCE API 請在
Authorization標頭帶入:Bearer <access_token>
isApiDsceEnabled 設為 1。/api/dsce/*。未開通時的回應:
HTTP/1.1 403 Forbidden
{ "code": "AccessDenied", "message": "PACT DSCE API access is not enabled for this account." }
確認 Token 是否仍有效,並取得 Token 內含的身份資訊。
POST/api/auth/tokenVerify
| 標頭 | 值 |
|---|---|
Authorization | Bearer <access_token> |
{
"valid": true,
"client_id": "dsce-a1b2c3d4",
"clientHost": "1.2.3.4",
"role": {
"roles": ["offline_access", "uma_authorization", "default-roles-demo"]
}
}
重新產生 client_secret,舊的密鑰立即失效。
PATCH/api/auth/credentials/{clientId}
| 標頭 | 值 |
|---|---|
Authorization | Bearer <access_token> |
| 參數 | 說明 |
|---|---|
clientId | 欲重置密鑰的 Client ID |
{
"client_id": "dsce-a1b2c3d4",
"client_secret": "NewSecretXyzAbc456"
}
⚠️ 重置後請更新所有使用舊憑證的系統,並重新取得 Token。
| 身分 | 可存取的資料範圍 |
|---|---|
| 一般 / 進階使用者 | 僅自身公司 (creator_company_serial = 自身) 的資料 |
| 資訊商 (ISP) | 自身 + 所有 Auth_Status = 1(已授權)代管客戶的資料 |
列表端點的 ?company_serial= 篩選:一般/進階使用者一律強制僅回傳自身,忽略此參數;資訊商指定時須為可存取範圍內的公司,否則回 403。
資訊商代表其代管客戶操作碳足跡與事件時,於 HTTP Header 帶入客戶公司序號:
X-On-Behalf-Of: {customerSn}
Auth_Status = 1。403。此標頭僅碳足跡(footprints)與事件(events)端點支援;公司與代理關係端點不使用。
僅資訊商可呼叫,用於建立客戶公司。客戶公司不存在→建立並同步發出 Auth_Status=0 待確認代理邀請;已存在→回 409,請改用 POST /api/dsce/provider 發邀請。
curl -X POST https://<host>/api/dsce/company \
-H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
-d '{ "agreeVer": true, "companyName": "客戶公司", "taxIDNumber": "12345678",
"contactName": "王小明", "contactEmail": "a@b.com", "isTaiwan": "Y" }'
公司列表。資訊商:自身 + Auth_Status=1 代管客戶;一般/進階使用者:僅自身。
取得 / 更新特定公司資料(須在可存取範圍內,否則 403)。
建立 / 發送代理邀請,預設 Auth_Status = 0(待確認)。Body:customer_serial。
解除代理關係。刪除前系統會先將該客戶公司的 Identity_Type 更新為 3(進階使用者),確保解綁後客戶仍可獨立操作,再刪除代理紀錄。
查詢代理關係清單,可用 ?Auth_Status= 篩選(0 待確認 / 1 已授權 / 2 已解除)。
代管操作須帶 X-On-Behalf-Of: {customerSn}。
| 方法 | 路徑 | 說明 |
|---|---|---|
| POST | /api/dsce/footprints | 建立碳足跡(歸屬目標公司) |
| PATCH | /api/dsce/footprints/{pfpId} | 廢棄碳足跡(Deprecated) |
| GET | /api/dsce/footprints | 列表,支援 ?company_serial=、?limit=、?offset= |
| GET | /api/dsce/footprints/{pfpId} | 取得單筆 |
| 方法 | 路徑 | 說明 |
|---|---|---|
| POST | /api/dsce/events | 建立碳排事件(歸屬目標公司,可代管) |
| GET | /api/dsce/events | 事件列表,支援 ?company_serial= |
| GET | /api/dsce/events/{id} | 取得單一事件 |
| HTTP | code | 常見情境 |
|---|---|---|
| 400 | BadRequest | 參數缺漏或格式錯誤 |
| 401 | TokenExpired | Token 無效或過期 |
| 402 | PaymentRequired | 帳號未啟用(isEnabled=0) |
| 403 | AccessDenied | 未開通 isApiDsceEnabled、或代管關係非 Auth_Status=1、或超出可存取範圍 |
| 404 | NotFound | 資料不存在或非可存取範圍(不洩漏存在與否) |
| 409 | Conflict | 建立公司時該公司已存在 |
| 500 | InternalError | 伺服器內部錯誤 |
錯誤回應格式:{ "code": "...", "message": "..." }
© 數位減碳雲資料交換平台(DSCE)· 本文件為 DSCE API 技術說明,UI 操作請見「使用者指南」。