# 列出虚拟货币余额

> 返回某个用户画像所有虚拟货币的当前余额。如果应用没有虚拟货币，`data` 为空数组。

## OpenAPI

```yaml
/api-specs/adapty-api.yaml get /api/v2/server-side-api/vc/balances/
openapi: 3.1.0
info:
  title: Adapty 服务端 API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: 生产服务器
paths:
  /api/v2/server-side-api/vc/balances/:
    get:
      summary: 列出虚拟货币余额
      description: |
        返回某个用户画像所有虚拟货币的当前余额。如果应用没有虚拟货币，`data` 为空数组。
      operationId: listVirtualCurrencyBalances
      tags:
        - Virtual Currency
      security:
        - apikeyAuth: []
      parameters:
        - name: adapty-customer-user-id
          in: header
          required: false
          schema:
            type: string
          description: 您系统中客户的唯一 ID。`adapty-customer-user-id` 或 `adapty-profile-id` 二者必填其一。
        - name: adapty-profile-id
          in: header
          required: false
          schema:
            type: string
          description: 您系统中用户画像的唯一 ID。如果您使用匿名用户画像，此字段为最佳选择。`adapty-customer-user-id` 或 `adapty-profile-id` 二者必填其一。
      responses:
        "200":
          description: 余额返回成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/VirtualCurrencyBalanceListResponse"
              example:
                response_created_at: 1779791400000
                data:
                  - code: COINS
                    name: Gold Coins
                    balance: 12450
                    held: 0
                    available: 12450
                  - code: GEMS
                    name: Gems
                    balance: 3280
                    held: 0
                    available: 3280
                  - code: ENERGY
                    name: Energy
                    balance: 840
                    held: 0
                    available: 840
        "400":
          description: 请求错误。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: 未授权。API 密钥缺失或无效。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: 禁止访问。此应用未启用虚拟货币服务端 API。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: 用户画像未找到。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: 服务器内部错误
components:
  schemas:
    VirtualCurrencyBalanceListResponse:
      type: object
      description: 用户画像所有虚拟货币的当前余额。
      properties:
        response_created_at:
          type: integer
          format: int64
          description: 响应生成的时间，以毫秒为单位的 Unix 时间戳。
        data:
          type: array
          items:
            $ref: "#/components/schemas/VirtualCurrencyProfileBalanceItem"
      required:
        - response_created_at
        - data
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              source:
                type: string
                nullable: true
                description: 错误来源
              errors:
                type: array
                items:
                  type: string
                description: 错误消息数组
        error_code:
          type: string
          description: 简短错误名称
        status_code:
          type: integer
          description: HTTP 状态码
      required:
        - errors
        - error_code
        - status_code
    VirtualCurrencyProfileBalanceItem:
      type: object
      properties:
        code:
          type: string
          description: 应用内唯一的虚拟货币代码。由 ASCII 字母、数字和下划线组成。
        name:
          type: string
          description: 虚拟货币的显示名称。
        balance:
          type: integer
          format: int32
          minimum: 0
          description: 总余额，包含当前被冻结的金额。
        held:
          type: integer
          format: int32
          minimum: 0
          description: 所有有效冻结金额的总和（已预留金额）。当前始终为 0。
        available:
          type: integer
          format: int32
          description: 可用于消费的余额，计算方式为 `balance - held`。
      required:
        - code
        - name
        - balance
        - held
        - available
  securitySchemes:
    apikeyAuth:
      type: apiKey
      name: Authorization
      in: header
      default: Api-Key {Your secret API key}
      description: |
        API 请求必须通过您的密钥进行身份验证，将其作为 **Authorization** 请求头，
        值为 `Api-Key {your_secret_api_key}`，例如 `Api-Key secret_live_...`。
        请在 Adapty 看板 -> **App Settings** -> **General** 标签页 -> **API keys** 部分找到此密钥。
```
