> ## Documentation Index
> Fetch the complete documentation index at: https://openapidocs.flexforwardship.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 身份驗證

> 如何驗證 Flex Forward API 請求

# 身份驗證

所有 Flex Forward API 端點都需要在 `Authorization` 標頭中使用 **Bearer 令牌** 進行身份驗證。

## 取得 API 令牌

API 存取令牌由 Flex Forward 團隊在建置或帳戶核准時發放。如需申請開發或正式環境的存取權限，請聯繫 [flex-forward.support@returnhelper.com](mailto:flex-forward.support@returnhelper.com)。

<Warning>
  請妥善保管您的 API 令牌。請勿在客戶端程式碼、公開儲存庫或不安全的管道中分享。
</Warning>

## 存取方式

Flex Forward 採用託管式建置模型。API 存取由 Flex Forward 團隊提供，以確保您的帳戶針對物流路線和物流業者需求正確設定。

<Steps>
  <Step title="聯繫 Flex Forward 團隊">
    將您的使用場景、預期配送量和所需物流路線以電子郵件發送至 [flex-forward.support@returnhelper.com](mailto:flex-forward.support@returnhelper.com)。
  </Step>

  <Step title="接收開發環境存取權限">
    團隊將提供您的開發環境認證資訊，並設定您的配送帳戶以在物流業者沙盒服務上進行測試。
  </Step>

  <Step title="測試您的整合">
    使用[開發環境](/zh-Hant/environments)建置並驗證您的整合。確認標籤建立、文件取得和追蹤功能正常。
  </Step>

  <Step title="申請正式環境存取權限">
    測試成功後，申請正式環境認證資訊。團隊將確認準備就緒並提供正式環境存取權限。
  </Step>
</Steps>

## 發送已驗證的請求

在每個請求的 `Authorization` 標頭中包含令牌：

```bash theme={null}
curl -X POST https://api.flexforward.com/labels \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "idempotencyKey": "ord-20250301-abc123",
    "courier": "yunexpress",
    "service": {
      "productCode": "HKMUZXR"
    },
    "shipment": { ... }
  }'
```

## 錯誤回應

令牌缺失或無效時，API 回傳 `401 Unauthorized` 回應：

```json theme={null}
{
  "error": "Unauthorized"
}
```

令牌有效但呼叫者無權存取請求的資源時，API 回傳 `403 Forbidden` 回應：

```json theme={null}
{
  "error": "Forbidden"
}
```

## 令牌最佳實踐

* 定期輪換令牌
* [開發和正式環境](/zh-Hant/environments)使用個別的令牌
* 將令牌存放在環境變數或密鑰管理器中 — 切勿寫死
