# 列出虚拟货币交易记录

> 返回用户画像的虚拟货币交易历史记录，按最新优先排序。结果使用游标分页：当响应包含非空的 `pagination.next_cursor` 时，将其作为 `cursor` 查询参数传回以获取下一页。

## OpenAPI

```yaml
/api-specs/adapty-api.yaml get /api/v2/server-side-api/vc/transactions/
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/transactions/:
    get:
      summary: 列出虚拟货币交易记录
      description: |
        返回用户画像的虚拟货币交易历史记录，按最新优先排序。结果使用游标分页：当响应包含非空的 `pagination.next_cursor` 时，将其作为 `cursor` 查询参数传回以获取下一页。
      operationId: listVirtualCurrencyTransactions
      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` 二者必填其一。
        - name: currency_code
          in: query
          required: false
          schema:
            type: string
          description: 将历史记录过滤为单个虚拟货币代码。
        - name: cursor
          in: query
          required: false
          schema:
            type: string
          description: 上一个响应中作为 `pagination.next_cursor` 返回的不透明分页游标。省略则获取第一页。
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            default: 50
            minimum: 1
            maximum: 100
          description: 每页返回的最大事务数。默认为 50。
      responses:
        "200":
          description: 交易历史记录返回成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/VirtualCurrencyTransactionsHistoryResponse"
              example:
                data:
                  - transaction_id: 0190e8a4-1c2b-7def-8abc-2c1a4b6d8e90
                    transaction_type: api_transaction
                    items:
                      - currency_code: COINS
                        amount: 500
                        balance_after: 12950
                    metadata:
                      reason: promo_bonus
                    created_at: "2026-05-23T10:30:00Z"
                  - transaction_id: 0190e7b2-9a44-7c10-bb31-7d2e9f0a1c55
                    transaction_type: store_purchase
                    items:
                      - currency_code: COINS
                        amount: 1000
                        balance_after: 12450
                    created_at: "2026-05-22T18:05:12Z"
                  - transaction_id: 0190e5c0-3f18-7b9a-9e6d-44a1c8b27e03
                    transaction_type: subscription_renewal
                    items:
                      - currency_code: GEMS
                        amount: 200
                        balance_after: 3280
                    created_at: "2026-05-20T09:00:00Z"
                pagination:
                  next_cursor: MjAyNi0wNS0yMFQwOTowMDowMFowMTkwZTVjMC0zZjE4LTdiOWEtOWU2ZC00NGExYzhiMjdlMDM=
        "400":
          description: 错误请求。`cursor` 值无效（`error_code` 为 `invalid_cursor`）。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: 未授权。API 密钥缺失或无效。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "403":
          description: 禁止访问。此应用未启用虚拟货币的 Server API。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: 未找到用户画像。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: 内部服务器错误
components:
  schemas:
    VirtualCurrencyTransactionsHistoryResponse:
      type: object
      description: 用户画像的虚拟货币交易记录分页列表。
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/VirtualCurrencyTransactionsHistoryItem"
        pagination:
          $ref: "#/components/schemas/VirtualCurrencyHistoryPagination"
      required:
        - data
        - pagination
    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
    VirtualCurrencyTransactionsHistoryItem:
      type: object
      properties:
        transaction_id:
          type: string
          format: uuid
          description: 交易的唯一 ID。
        transaction_type:
          type: string
          description: |
            交易的来源。可选值为 `store_purchase`、`subscription_renewal`、`trial_start`、`api_transaction`、`dashboard_transaction`、`refund` 或 `expiry`。
        items:
          type: array
          description: 本次交易中记录的各币种余额变动。
          items:
            $ref: "#/components/schemas/VirtualCurrencyBalanceChange"
        metadata:
          type: object
          nullable: true
          additionalProperties:
            type: string
          description: 与交易一同存储的键值对（如有）。
        created_at:
          type: string
          format: date-time
          description: 交易的记录时间。
      required:
        - transaction_id
        - transaction_type
        - items
        - created_at
    VirtualCurrencyHistoryPagination:
      type: object
      properties:
        next_cursor:
          type: string
          nullable: true
          description: |
            下一页的不透明游标。将其作为 `cursor` 查询参数传递以获取更多结果。当没有更多页面时为 Null。
      required:
        - next_cursor
    VirtualCurrencyBalanceChange:
      type: object
      properties:
        currency_code:
          type: string
          description: 虚拟货币代码。
        amount:
          type: integer
          format: int32
          description: 应用于余额的带符号变动量。正值为充值，负值为扣除。
        balance_after:
          type: integer
          format: int32
          minimum: 0
          description: 本次交易应用后的货币余额。
      required:
        - currency_code
        - amount
        - balance_after
  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** 部分找到此密钥。
```
