# asc

> 在團隊中使用的 App Store Connect 命令列：如何選擇 Apple 團隊、輸出格式、分頁、結束代碼，以及所有指令系列。

Source: https://air.build/tw/docs/cli/asc/

`asc` 是 App Store Connect 的命令列工具，涵蓋 App、版本、中繼資料、截圖、建置版本、TestFlight、審查、App 內購買項目、訂閱、定價、簽署資源、報告等。在 AirBuild 中，它在團隊的環境裡執行，雲端團隊與 Mac 團隊皆可使用，且一律使用團隊擁有者在 AirBuild 中連接的 Apple 團隊。

本頁說明所有指令共通的部分：選擇 Apple 團隊、旗標、輸出、分頁與結束代碼。各指令系列列在文末，並附上各自頁面的連結。

## 用法摘要

```bash
asc <command> [<subcommand> ...] [flags]
asc <command> --help
asc --version
```

每個指令與子指令都有 `--help`。`asc search "<what you want to do>"` 可以依工作找到對應的指令（請參閱[尋找指令](https://air.build/tw/docs/cli/asc/#finding-commands)）。

## 開始使用

```bash
asc auth list                                # the connected Apple teams and their --auth names
asc apps list --paginate --output table      # your apps and their IDs
asc status --app APP_ID                      # one-screen release overview of an app
```

多數指令需要資源 ID，例如 App ID、版本 ID 或建置版本 ID，可用 `list` 指令查到。指令中出現 `APP_ID` 或類似的寫法時，請換成實際的值。

## Apple 團隊與 --auth

`asc` 本身不保存任何 Apple 金鑰，也從不自行登入 Apple。團隊擁有者在 AirBuild 中連接 Apple Developer 帳號，並開啟團隊可使用的 Apple 團隊（請參閱[連結你的 Apple 開發者帳號](https://air.build/tw/docs/app-store/connect-apple-developer-account/)）。之後每個 `asc` 請求都會透過 AirBuild，以其中一個 Apple 團隊的身分送出。團隊成員及其 Agent 使用的是擁有者連接的 Apple 團隊。

`asc auth list` 以 Tab 分隔的表格列出這些團隊：

```text
AUTH        APPLE TEAM          TEAM ID
my-company  My Company, Inc.    A1B2C3D4E5
side-apps   Jane Appleseed      F6G7H8I9J0

Select one per command: asc <command> --auth <name>
```

| 欄位 | 意義 |
| --- | --- |
| `AUTH` | 傳給 `--auth` 的名稱。 |
| `APPLE TEAM` | Apple 團隊的名稱。 |
| `TEAM ID` | Apple 的 Team ID。 |

每次執行 `asc auth list` 都會重新取得清單。

指令會使用哪個 Apple 團隊：

| 已連接的 Apple 團隊 | 結果 |
| --- | --- |
| 無 | 指令失敗：`no App Store Connect credentials are connected for this Team.` 請團隊擁有者連接一個後再執行。 |
| 一個 | 直接使用該團隊，不需要 `--auth`。 |
| 多個 | 每個指令都要加上 `--auth <name>`，或在 shell 中設定 `ASC_AUTH=<name>`。兩者皆無時，指令會失敗並列出可用的名稱。 |

`--auth` 可以放在指令名稱之前或之後：`asc --auth my-company apps list` 與 `asc apps list --auth my-company` 效果相同。

`asc web` 底下的指令，以及說明中標示為「Airbuild-served」的少數其他指令，會使用 AirBuild 保存的團隊擁有者 Apple 登入工作階段，處理 Apple API 未涵蓋的 App Store Connect 與 Developer Portal 功能。`asc web auth status` 會顯示所選 Apple 團隊的這個工作階段。`asc` 從不要求輸入 Apple 密碼或驗證碼。

## 全域旗標

| 旗標 | 值 | 預設 | 作用 |
| --- | --- | --- | --- |
| `--auth` | `asc auth list` 中的名稱 | 唯一已連接的團隊 | 要使用的 Apple 團隊。也可用 `ASC_AUTH`。 |
| `--read-only` | — | 關閉 | 在送出前拒絕所有變更（POST、PATCH、PUT、DELETE）。`ASC_READ_ONLY=1` 效果相同。被拒絕的請求以 `6` 結束。 |
| `--strict-auth` | — | 關閉 | 若 Apple 團隊可從多個來源判定，則直接失敗。 |
| `--debug` | — | 關閉 | 將除錯記錄輸出到 stderr。 |
| `--api-debug` | — | 關閉 | 將 HTTP 除錯記錄輸出到 stderr，敏感值會遮蔽。 |
| `--retry-log` | — | 關閉 | 將重試記錄輸出到 stderr（優先於 `ASC_RETRY_LOG`）。 |
| `--report` | 格式，例如 `junit` | 無 | 以該格式寫出 CI 報告。 |
| `--report-file` | 路徑 | 無 | `--report` 檔案的寫入位置。 |
| `--version` | — | — | 印出版本後結束（`asc version` 效果相同）。 |

### 從環境變數或檔案取值

任何需要值的旗標都接受 `@env:NAME`（環境變數的值）或 `@file:PATH`（檔案內容）。若值本身確實以 `@` 開頭，請寫成 `@@`。`--output`、`--auth`、`--report` 與 `--report-file` 一律照字面讀取。

```bash
asc review details-update --id "DETAIL_ID" --demo-account-password @env:DEMO_PASSWORD
```

## 變更需要 --confirm

會刪除、取代、提交或發布內容的指令都需要 `--confirm`，否則會拒絕執行。其中許多也支援 `--dry-run`，只顯示會發生什麼而不做任何變更。`asc` 從不中途停下來詢問問題。

## 輸出

| 旗標 | 值 | 預設 | 作用 |
| --- | --- | --- | --- |
| `--output` | `json`、`table`、`markdown` | 見下文 | 輸出格式。其他值會失敗：`--output must be one of: json, table, markdown (got "yaml")`。 |
| `--pretty` | — | 關閉 | 將 JSON 縮排。 |

輸出到終端機時預設為 `table`；透過管線傳遞、被擷取或在 CI 中執行時預設為 `json`，Agent 就屬於後者。`ASC_DEFAULT_OUTPUT`（`json`、`table`、`markdown` 或 `md`）可設定不同的預設值。說明頁面顯示的是 `(default: json)`。

資料輸出到 stdout；警告、進度與錯誤輸出到 stderr，因此 stdout 上的 JSON 可以直接解析。

讀取 App Store Connect 資源的指令會印出 Apple 的 JSON:API 格式：

```json
{
  "data": [
    { "type": "apps", "id": "1234567890", "attributes": { "name": "…", "bundleId": "com.example.app", "sku": "…", "primaryLocale": "en-US" } }
  ],
  "links": { "self": "https://api.appstoreconnect.apple.com/v1/apps?…", "next": "https://api.appstoreconnect.apple.com/v1/apps?…&cursor=…" },
  "meta": { "paging": { "total": 18, "limit": 1 } }
}
```

單一資源時，`data` 是一個物件；ID 位於 `data.id` 或 `data[].id`。工作流程指令（`status`、`validate`、`release stage`、`publish …` 等）則印出各自的摘要物件，格式請見其說明。

## 分頁

列表指令一次回傳一頁。

| 旗標 | 值 | 預設 | 作用 |
| --- | --- | --- | --- |
| `--limit` | 1 至 200 | Apple 的每頁數量 | 每頁結果數。 |
| `--paginate` | — | 關閉 | 取得所有頁面，合併成一個結果印出。 |
| `--next` | `links.next` URL | — | 取得印出該 URL 那一頁的下一頁。 |

若還有其他頁面而你沒有要求取得，stderr 會提示：

```text
Warning: showing 1 of 18 results; more pages exist (use --paginate or --next where supported)
```

需要完整清單時（例如要找舊版本或舊建置版本），請加上 `--paginate`。

## 環境變數

| 變數 | 作用 |
| --- | --- |
| `ASC_AUTH` | Apple 團隊，同 `--auth`。 |
| `ASC_APP_ID` | 說明中標示「or ASC_APP_ID」的指令所用的 `--app` 預設值。 |
| `ASC_DEFAULT_OUTPUT` | 預設輸出格式。 |
| `ASC_READ_ONLY` | 設為 `1` 時拒絕所有變更，同 `--read-only`。 |
| `ASC_TIMEOUT` / `ASC_TIMEOUT_SECONDS` | 請求逾時，可寫成時間長度（`90s`）或整數秒數。預設 30 秒。 |
| `ASC_UPLOAD_TIMEOUT` / `ASC_UPLOAD_TIMEOUT_SECONDS` | 上傳逾時，寫法相同。預設 300 秒。 |
| `ASC_RETRY_LOG` | 將重試記錄輸出到 stderr。 |

## 結束代碼

| 代碼 | 意義 | 處理方式 |
| --- | --- | --- |
| `0` | 成功。 | — |
| `1` | 其他錯誤，包括就緒檢查未通過（`validate`、`release stage`）。 | 閱讀 stderr 上的訊息。 |
| `2` | 用法錯誤：未知的指令或旗標、缺少值或值不正確。此外：未連接任何 Apple 團隊、`--auth` 名稱不存在，或有多個團隊卻未指定 `--auth`。 | 修正指令；`--help` 會列出旗標。未知旗標會附上建議。 |
| `3` | 未獲授權：Apple 拒絕、Apple 登入需要擁有者處理，或有 Apple 協議等待接受。 | 請參閱[錯誤](https://air.build/tw/docs/cli/asc/#errors)。 |
| `4` | 找不到。 | 確認 ID；可用 `list` 指令查詢。 |
| `5` | 衝突：資源已存在，或另一個 Apple 帳號作業正在進行。 | 閱讀訊息。部分 `create` 指令支援 `--if-exists skip` 或 `update`。 |
| `6` | `--read-only` / `ASC_READ_ONLY` 拒絕了變更。 | 若確實要變更，請不要使用唯讀模式執行。 |
| `7` | 有限時的等待在達到目標前結束（`status --until`、`builds wait --report-pending`）。 | 再次執行印出的指令以繼續等待。 |
| `10`–`59` | Apple 回傳的其他 HTTP 4xx：10 +（狀態碼 − 400），例如 400 為 `10`、422 為 `32`。 | 閱讀訊息中 Apple 的錯誤說明。 |
| `60`–`99` | Apple 回傳的 HTTP 5xx：60 +（狀態碼 − 500），例如 503 為 `63`。 | Apple 端發生問題，請稍後再試。`asc system-status` 會顯示 Apple 的服務狀態。 |

## 錯誤

錯誤會以 `Error: <reason>` 的形式印在 stderr，通常接著說明下一步該怎麼做。

| 訊息 | 結束代碼 | 處理方式 |
| --- | --- | --- |
| `no App Store Connect credentials are connected for this Team.` | 2 | 由團隊擁有者在 **設定** › **開發者** 中連接 Apple Developer 帳號並開啟一個團隊，然後再次執行指令。 |
| `several Apple teams are connected; pass --auth <name>. Connected auths: …` | 2 | 加上 `--auth <name>` 或設定 `ASC_AUTH`。 |
| ``unknown auth '<name>'. Connected auths: …. Run `asc auth list`.`` | 2 | 使用列出的其中一個名稱。 |
| `could not reach Airbuild to fetch the connected Apple teams.` | 1 | 網路問題，請再試一次。 |
| Apple 登入需要擁有者處理（已通知對方）。 | 3 | 團隊擁有者在 **設定** › **開發者** › **重新登入** 中重新登入。待對方確認後再執行指令。 |
| Apple 登入已過期，目前無法恢復。 | 3 | 再試一次。若持續失敗，請團隊擁有者重新登入。 |
| 另一個 Apple 帳號作業正在進行。 | 5 | 等候約一分鐘後再執行。 |
| Apple 在協議接受前拒絕該團隊。 | 3 | 不要重試。由該 Apple 團隊的 Account Holder 接受協議，可在 AirBuild 中重新設定該團隊，或前往 developer.apple.com/account。`asc web agreements status` 會顯示待處理的項目。Apple 會在幾分鐘內套用接受結果。 |
| 協議已接受，Apple 正在套用。 | 3 | 約五分鐘後再次執行指令。 |
| ``unknown command `asc …` `` | 2 | 用 `asc --help` 或 `asc search` 確認名稱。 |
| ``unknown flag `--x` for `asc …` `` | 2 | 使用建議的旗標，或閱讀 `asc <command> --help`。 |
| `--app is required (or set ASC_APP_ID)` | 2 | 加上 `--app`。許多指令接受 App ID、Bundle ID 或完整的 App 名稱。 |

## 尋找指令

| 指令 | 作用 |
| --- | --- |
| `asc search [--limit N] "<query>"` | 搜尋指令、說明、範例與旗標名稱（不搜尋 App Store Connect 資料）。預設 10 筆結果。 |
| `asc capabilities [--area A,B] [--status S]` | 顯示 `asc` 涵蓋哪些 App Store Connect 工作：`cli-supported`、`partial`、`not-public-api`（Apple 的 API 無法做到）或 `manual`（需由人員在 Apple 網站操作；`nextAction` 說明該如何告知對方）。 |
| `asc schema [--method M] [--list] <query>` | 以 JSON 查詢 App Store Connect API 端點：參數、屬性、關聯與回應類型。可依路徑（`apps`）、方法加路徑（`"GET /v1/apps"`）或動作（`apps.list`、`v2.gameCenterAchievements.get`）查詢。 |
| `asc api <METHOD> <PATH> [--query k=v] [--body JSON] [--paginate] [--confirm]` | 以所選 Apple 團隊向 App Store Connect API 送出原始請求，並原樣印出 Apple 的 JSON。可用 `--body-file F` 取代 `--body JSON`。除非加上 `--allow-unknown-path`，路徑必須存在於 schema 索引中。所有非 GET 請求都需要 `--confirm`。`--paginate`（僅限 GET）會合併所有頁面。 |
| `asc system-status [--service S] [--issues-only] [--watch]` | Apple Developer 系統狀態。不需要 Apple 團隊。 |
| `asc docs list` / `asc docs show <guide>` | 內建參考指南。 |
| `asc version` | 印出版本。 |
| `asc completion --shell SHELL`（`bash`、`zsh` 或 `fish`） | 印出 shell 自動完成指令碼。 |

另有兩組工具指令：`asc diff localizations` 比較本機檔案與某個版本、或兩個版本之間的在地化中繼資料，不做任何變更；`asc snitch` 會針對 `asc` 本身的問題草擬 GitHub issue（`--dry-run` 或 `--local` 只預覽或記錄，`--confirm` 才會送出）。`asc telemetry status|enable|disable|reset-id` 雖然存在，但在 AirBuild 中 `asc` 不會傳送任何遙測資料。

## 指令系列

| 頁面 | 系列 |
| --- | --- |
| [asc：App 與 App Store 頁面](https://air.build/tw/docs/cli/asc-apps/) | `apps`, `app-setup`, `app-tags`, `versions`, `localizations`, `metadata`, `screenshots`, `video-previews`, `asset-library`, `background-assets`, `product-pages`, `routing-coverage`, `pricing`, `pre-orders`, `categories`, `age-rating`, `accessibility`, `encryption`, `eula`, `agreements`, `app-clips`, `android-ios-mapping`, `marketplace`, `alternative-distribution`, `nominations`, `game-center` |
| [asc：建置版本與 TestFlight](https://air.build/tw/docs/cli/asc-builds/) | `builds`, `testflight`, `build-bundles`, `build-localizations`, `distribute`, `ipa-info`, `pkg-info`, `sandbox` |
| [asc：審查與發布](https://air.build/tw/docs/cli/asc-release/) | `status`, `validate`, `publish`, `release`, `review`, `submit`, `reviews`, `release-notes` |
| [asc：App 內購買與訂閱](https://air.build/tw/docs/cli/asc-monetization/) | `iap`, `subscriptions`, `app-events`, `storekit` |
| [asc：簽署、裝置與使用者](https://air.build/tw/docs/cli/asc-signing/) | `bundle-ids`, `certificates`, `profiles`, `merchant-ids`, `pass-type-ids`, `app-clip-ids`, `notarization`, `devices`, `users`, `actors`, `account` |
| [asc：分析與財務](https://air.build/tw/docs/cli/asc-analytics/) | `analytics`, `finance`, `vendor-number`, `insights`, `performance`, `optimize` |
| [asc：網頁工作階段指令](https://air.build/tw/docs/cli/asc-web/) | `web` |
| [asc：自動化](https://air.build/tw/docs/cli/asc-automation/) | `workflow`, `webhooks`, `xcode-cloud`, `notify`, `migrate` |

## 範例

查看可使用的 Apple 團隊，再列出其中一個團隊的 App：

```bash
asc auth list
asc apps list --auth my-company --paginate --output table
```

查看某個 App 最新的建置版本，並等待處理完成：

```bash
asc builds info --app "com.example.app" --latest --platform IOS
asc builds wait --app "com.example.app" --latest --timeout 30m
```

安全地瀏覽，拒絕任何變更：

```bash
asc --read-only status --app "APP_ID" --output table
```

以 JSON 讀取某個 App 的所有 TestFlight 群組，供指令碼使用：

```bash
asc testflight groups list --app "APP_ID" --paginate --output json --pretty
```
