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

# 获取所有交易

## 概览

Transactions API 允许你检索与你的账户关联的所有金融交易的完整历史。这包括购买、存款、取款、转账、账单支付以及所有其他金融活动。

**端点类型**: GraphQL 查询\
**身份验证**: 必需（JWT Bearer Token）\
**所需范围**: `LIST_PAYMENT` AND `LIST_PURCHASES`\
**速率限制**: 适用标准 GraphQL 速率限制

***

## 快速开始

### 基本查询

```graphql theme={null}
query GetTransactions {
  getTransactions {
    transactions {
      recordId
      transactionType
      amount
      status
      channel
      connectedAppId
      connectedAppName
      createdAt
    }
    totalCount
    hasNextPage
  }
}
```

<br />

***

## 查询结构

```graphql theme={null}
getTransactions(
  filter: TransactionFilterInput
  paginate: OffsetInput
): TransactionConnection!
```

### 参数

| 参数         | 类型                       | 是否必填 | 描述                          |
| ---------- | ------------------------ | ---- | --------------------------- |
| `filter`   | `TransactionFilterInput` | 否    | 交易的筛选条件                     |
| `paginate` | `OffsetInput`            | 否    | 分页参数（默认：limit=20, offset=0） |

***

## 响应结构

### TransactionConnection

```graphql theme={null}
type TransactionConnection {
  transactions: [Transaction]
  totalCount: Int!
  hasNextPage: Boolean!
}
```

| 字段             | 类型              | 描述                |
| -------------- | --------------- | ----------------- |
| `transactions` | `[Transaction]` | 交易记录数组            |
| `totalCount`   | `Int!`          | 符合筛选条件的交易总数（用于分页） |
| `hasNextPage`  | `Boolean!`      | 是否还有更多结果          |

***

## 筛选选项

### TransactionFilterInput

```graphql theme={null}
input TransactionFilterInput {
  # Record & Status
  recordId: [UUID]
  status: [TransactionStatus]
  
  # Amount Filters
  amount: Float
  amountGte: Float
  amountLte: Float
  finalAmount: Float
  finalAmountGte: Float
  finalAmountLte: Float
  
  # Cashback Filters
  cashbackAmount: Float
  cashbackAmountGte: Float
  cashbackAmountLte: Float
  cashbackPercentage: Float
  cashbackPercentageGte: Float
  cashbackPercentageLte: Float
  
  # Fee Filters
  feeAmount: Float
  feeAmountGte: Float
  feeAmountLte: Float
  
  # Date Filters
  createdGte: DateTime
  createdLte: DateTime
  updatedGte: DateTime
  updatedLte: DateTime
  
  # Merchant Filters
  merchantId: [UUID]
  merchant: [String]
  
  # Transaction Properties
  transactionType: [String]
  channel: [String!]
  category: [String]
  
  # Virtual Card Filters
  virtualCardProgram: [String]
  virtualCard: [UUID]
  
  # Other
  fundingSource: [String]
  userCashBalanceId: [UUID]
  referenceId: String
  liabilityId: UUID
}
```

### 筛选字段详情

#### 记录与状态筛选

##### `recordId`

**类型**: `[UUID]`\
**描述**: 按特定交易记录 ID 进行筛选。

**示例**:

```graphql theme={null}
filter: {
  recordId: ["550e8400-e29b-41d4-a716-446655440000"]
}
```

##### `status`

**类型**: `[TransactionStatus]`\
**描述**: 按交易状态进行筛选。

**选项**:

* `PENDING` - 交易处理中
* `SETTLED` - 交易已成功完成

**示例**:

```graphql theme={null}
filter: {
  status: [SETTLED]
}
```

***

#### 金额筛选

##### `amount`, `amountGte`, `amountLte`

**类型**: `Float`\
**描述**: 按美元的精确金额或金额区间进行筛选。

* `amount` - 精确金额匹配
* `amountGte` - 最小金额（大于等于）
* `amountLte` - 最大金额（小于等于）

**示例**:

```graphql theme={null}
# Transactions between $10 and $500
filter: {
  amountGte: 10.00
  amountLte: 500.00
}
```

##### `finalAmount`, `finalAmountGte`, `finalAmountLte`

**类型**: `Float`\
**描述**: 按最终金额（金额 + 手续费）筛选。

**示例**:

```graphql theme={null}
filter: {
  finalAmountGte: 25.00
}
```

***

#### 返现筛选

##### `cashbackAmount`, `cashbackAmountGte`, `cashbackAmountLte`

**类型**: `Float`\
**描述**: 按获得的返现金额进行筛选。

**示例**:

```graphql theme={null}
# Transactions that earned $5 or more in cashback
filter: {
  cashbackAmountGte: 5.00
}
```

##### `cashbackPercentage`, `cashbackPercentageGte`, `cashbackPercentageLte`

**类型**: `Float`\
**描述**: 按返现比例（百分比）进行筛选。

**示例**:

```graphql theme={null}
# Transactions with 5% or higher cashback
filter: {
  cashbackPercentageGte: 5.0
}
```

***

#### 手续费筛选

##### `feeAmount`, `feeAmountGte`, `feeAmountLte`

**类型**: `Float`\
**描述**: 按交易手续费金额进行筛选。

**示例**:

```graphql theme={null}
# Transactions with fees
filter: {
  feeAmountGte: 0.01
}
```

***

#### 日期筛选

##### `createdGte`, `createdLte`

**类型**: `DateTime`\
**格式**: ISO 8601（例如，`2025-01-01T00:00:00Z`）\
**描述**: 按交易创建时间范围筛选。

**示例**:

```graphql theme={null}
filter: {
  createdGte: "2025-01-01T00:00:00Z"
  createdLte: "2025-01-31T23:59:59Z"
}
```

##### `updatedGte`, `updatedLte`

**类型**: `DateTime`\
**描述**: 按交易最后更新时间范围筛选。

***

#### 商户筛选

##### `merchantId`

**类型**: `[UUID]`\
**描述**: 按特定商户 ID 进行筛选。

**示例**:

```graphql theme={null}
filter: {
  merchantId: ["550e8400-e29b-41d4-a716-446655440000"]
}
```

##### `merchant`

**类型**: `[String]`\
**描述**: 按商户名称进行筛选（与 destination 字段匹配）。

**示例**:

```graphql theme={null}
filter: {
  merchant: ["Amazon", "Walmart"]
}
```

***

#### 交易属性

##### `transactionType`

**类型**: `[String]`\
**描述**: 按特定交易类型筛选。

**常见值**:

* `Add Money` - 存款
* `Gift Card Purchase` - 礼品卡购买
* `Transfer - In` - 转入
* `Transfer - Out` - 转出
* `Virtual Card Purchase` - 虚拟卡购买
* `Withdrawal`

<br />

**示例**:

```graphql theme={null}
filter: {
  transactionType: ["Gift Card Purchase", "Add Money"]
}
```

##### `channel`

**类型**: `[String!]`\
**描述**: 按平台渠道筛选。

**常见值**:

* `WEB` - 网页
* `MOBILE` - 移动应用
* `API` - API 请求

**示例**:

```graphql theme={null}
filter: {
  channel: ["WEB", "MOBILE"]
}
```

##### `category`

**类型**: `[String]`\
**描述**: 按交易类别筛选。

**示例**:

```graphql theme={null}
filter: {
  category: ["Shopping", "Travel"]
}
```

***

#### 虚拟卡筛选

##### `virtualCardProgram`

**类型**: `[String]`\
**描述**: 按虚拟卡项目/发卡方筛选。

**示例**:

```graphql theme={null}
filter: {
  virtualCardProgram: ["TRANSPECOS", "SUTTON"]
}
```

##### `virtualCard`

**类型**: `[UUID]`\
**描述**: 按特定虚拟卡 ID 筛选。

**示例**:

```graphql theme={null}
filter: {
  virtualCard: ["vc-1", "vc-2"]
}
```

***

#### 其他筛选

##### `fundingSource`

**类型**: `[String]`\
**描述**: 搜索资金来源名称（对来源或去向进行部分匹配）。

**示例**:

```graphql theme={null}
filter: {
  fundingSource: ["Visa"]
}
```

##### `referenceId`

**类型**: `String`\
**描述**: 按外部参考 ID（例如购买展示 ID）筛选。

**示例**:

```graphql theme={null}
filter: {
  referenceId: "1000123"
}
```

##### `liabilityId`

**类型**: `UUID`\
**描述**: 按负债 ID 筛选（用于账单支付）。

***

## 分页

### OffsetInput

```graphql theme={null}
input OffsetInput {
  limit: Int = 20
  offset: Int = 0
}
```

| 字段       | 类型  | 默认值 | 最大值 | 描述        |
| -------- | --- | --- | --- | --------- |
| `limit`  | Int | 20  | 20  | 每页返回的交易数量 |
| `offset` | Int | 0   | -   | 要跳过的交易数量  |

**示例 - 第 1 页**:

```graphql theme={null}
paginate: {
  limit: 20
  offset: 0
}
```

**示例 - 第 2 页**:

```graphql theme={null}
paginate: {
  limit: 20
  offset: 20
}
```

**示例 - 检查是否存在更多页面**:

```graphql theme={null}
query GetTransactions {
  getTransactions(paginate: { limit: 20, offset: 0 }) {
    transactions { record_id }
    hasNextPage  # Use this to determine if there are more results
    totalCount   # Total matching records
  }
}
```

***

## 交易类型

```graphql theme={null}
type Transaction {
  record_id: UUID
  user: String!
  account_id: UUID!
  user_id: UUID
  transaction_type: String
  amount: Float!
  destination: String
  source: String
  external_funding_source_activity: Float
  fluz_balance_activity: Float
  fee: Float
  cashback: Float
  
  # Ending balances after transaction
  gift_card_prepayment_balance_available_balance: Float
  gift_card_prepayment_balance_total_balance: Float
  cash_balance_available_balance: Float
  cash_balance_total_balance: Float
  seat_balance_available_balance: Float
  seat_balance_total_balance: Float
  reserve_balance_available_balance: Float
  reserve_balance_total_balance: Float
  other_cash_balance_available_balance: Float
  other_cash_balance_total_balance: Float
  
  status: TransactionStatus
  reference_id: String
  description: String
  note: String
  category: String
  card_last_four: String
  card_display_name: String
  original_currency_amount: Float
  original_currency_code: String
  conversion_rate: Float
  merchant_id: UUID
  descriptor_id: UUID
  virtual_card_program: String
  cashback_rate: Float
  bonus_cashback_rate: Float
  channel: String
  source_type: String
  logo_url: String
  platformInstitutionLogo: String
  challengeLogoUrl: String
  invitedAccountId: UUID
  expectedClearedDate: DateTime
  liability_id: UUID
  is_gift_card_balance_affected: Boolean
  is_cash_balance_affected: Boolean
  is_seat_balance_affected: Boolean
  is_reserve_balance_affected: Boolean
  transfer_id: UUID
  used_user_cash_balance_id: UUID
  connectedAppId: UUID
  connectedAppName: String
  
  memo: String
  transactionCategory: String
  attachmentUrl: String

  created_at: DateTime
  updated_at: DateTime
}
```

### 字段描述

#### 核心交易字段

| 字段                 | 类型                | 描述                                |
| ------------------ | ----------------- | --------------------------------- |
| `record_id`        | UUID              | 此交易记录的唯一标识符                       |
| `user`             | String            | 与该交易关联的用户显示名称                     |
| `account_id`       | UUID              | 拥有该交易的账户                          |
| `user_id`          | UUID              | 发起该交易的用户                          |
| `transaction_type` | String            | 交易类型（PURCHASE、DEPOSIT 等）          |
| `amount`           | Float             | 以美元计的主要交易金额                       |
| `source`           | String            | 资金来源（例如，“Bank Card \*\*\*\*1234”） |
| `destination`      | String            | 资金去向（例如，商户名称）                     |
| `status`           | TransactionStatus | 当前状态（PENDING 或 SETTLED）           |

#### 财务明细

| 字段                                 | 类型    | 描述                |
| ---------------------------------- | ----- | ----------------- |
| `external_funding_source_activity` | Float | 外部资金来源（银行卡/账户）的变动 |
| `fluz_balance_activity`            | Float | Fluz 内部余额的变动      |
| `fee`                              | Float | 此笔交易收取的手续费        |
| `cashback`                         | Float | 此笔交易获得的返现         |
| `cashback_rate`                    | Float | 返现比例（百分比）         |
| `bonus_cashback_rate`              | Float | 额外奖励返现比例          |

#### 余额快照

**重要**: 所有余额字段均显示此交易应用后的余额。

| 字段                                               | 描述          |
| ------------------------------------------------ | ----------- |
| `cash_balance_available_balance`                 | 交易后可用现金余额   |
| `cash_balance_total_balance`                     | 交易后现金总余额    |
| `seat_balance_available_balance`                 | 交易后可用奖励余额   |
| `seat_balance_total_balance`                     | 交易后奖励总余额    |
| `gift_card_prepayment_balance_available_balance` | 交易后可用预付余额   |
| `gift_card_prepayment_balance_total_balance`     | 交易后预付总余额    |
| `reserve_balance_available_balance`              | 交易后可用准备金余额  |
| `reserve_balance_total_balance`                  | 交易后准备金总余额   |
| `other_cash_balance_available_balance`           | 交易后其他现金可用余额 |
| `other_cash_balance_total_balance`               | 交易后其他现金总余额  |

#### 交易详情

| 字段                    | 类型     | 描述                                                                                                                                 |
| :-------------------- | :----- | :--------------------------------------------------------------------------------------------------------------------------------- |
| `reference_id`        | String | 外部参考（例如购买展示 ID）                                                                                                                    |
| `description`         | String | 人类可读的描述                                                                                                                            |
| `note`                | String | 附加备注                                                                                                                               |
| `category`            | String | 交易类别                                                                                                                               |
| `card_last_four`      | String | 所用卡片的后 4 位（如适用）                                                                                                                    |
| `card_display_name`   | String | 支付方式的展示名称                                                                                                                          |
| `memo`                | String | 附加在此交易上的自由文本备注。可通过 [`updateTransactionMetadata`](/features/add-expense-details) 设置，或在存款、购买、转账时设置。                                  |
| `transactionCategory` | String | 附加在此交易上的类别标签。可通过 [`updateTransactionMetadata`](/features/add-expense-details) 设置，或在存款、购买、转账时设置。                                    |
| `attachmentUrl`       | String | 附加在此交易的文件的签名 URL。可通过 [`updateTransactionMetadata`](/features/add-expense-details) 设置，或在交易时设置。**此 URL 会过期 — 请勿存储。** 当需要访问文件时重新获取交易。 |

#### 商户信息

| 字段              | 类型     | 描述             |
| --------------- | ------ | -------------- |
| `merchant_id`   | UUID   | 商户标识符          |
| `descriptor_id` | UUID   | 交易描述符 ID       |
| `logo_url`      | String | 指向商户/来源徽标的 URL |

#### 虚拟卡信息

| 字段                     | 类型     | 描述                      |
| ---------------------- | ------ | ----------------------- |
| `virtual_card_program` | String | 虚拟卡项目（LITHIC、MARQETA 等） |

#### 货币转换

| 字段                         | 类型     | 描述               |
| -------------------------- | ------ | ---------------- |
| `original_currency_amount` | Float  | 原始货币金额（用于外币交易）   |
| `original_currency_code`   | String | 原始货币代码（例如，“EUR”） |
| `conversion_rate`          | Float  | 应用的汇率            |

#### 元数据

| 字段                              | 类型       | 描述                   |
| ------------------------------- | -------- | -------------------- |
| `channel`                       | String   | 平台渠道（WEB、MOBILE、API） |
| `source_type`                   | String   | 资金来源类型               |
| `liability_id`                  | UUID     | 关联负债（用于账单支付）         |
| `transfer_id`                   | UUID     | 关联转账（用于 P2P）         |
| `used_user_cash_balance_id`     | UUID     | 使用的特定现金余额            |
| `is_gift_card_balance_affected` | Boolean  | 礼品卡余额是否发生变化          |
| `is_cash_balance_affected`      | Boolean  | 现金余额是否发生变化           |
| `is_seat_balance_affected`      | Boolean  | 奖励余额是否发生变化           |
| `is_reserve_balance_affected`   | Boolean  | 准备金余额是否发生变化          |
| `connectedAppId`                | UUID     | 关联的应用 ID             |
| `connectedAppName`              | String   | 关联的应用名称              |
| `created_at`                    | DateTime | 交易的创建时间              |
| `updated_at`                    | DateTime | 交易的最后更新时间            |

***

## 示例

### 示例 1：基础交易列表

**查询**:

```graphql theme={null}
query GetRecentTransactions {
  getTransactions(
    paginate: { limit: 10, offset: 0 }
  ) {
    transactions {
      record_id
      transaction_type
      amount
      description
      status
      cashback
      created_at
    }
    totalCount
    hasNextPage
  }
}
```

**响应**:

```json theme={null}
{
  "data": {
    "getTransactions": {
      "transactions": [
        {
          "record_id": "550e8400-e29b-41d4-a716-446655440000",
          "transaction_type": "GIFT_CARD_PURCHASE",
          "amount": 50.00,
          "description": "Gift card purchase at Amazon",
          "status": "SETTLED",
          "cashback": 2.50,
          "created_at": "2025-01-15T14:30:00Z"
        },
        {
          "record_id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
          "transaction_type": "DEPOSIT",
          "amount": 100.00,
          "description": "Cash Balance Deposit",
          "status": "SETTLED",
          "cashback": 0.00,
          "created_at": "2025-01-14T10:15:00Z"
        }
      ],
      "totalCount": 2,
      "hasNextPage": false
    }
  }
}
```

***

### 示例 2：按日期范围筛选

**查询**:

```graphql theme={null}
query GetJanuaryTransactions {
  getTransactions(
    filter: {
      createdGte: "2025-01-01T00:00:00Z"
      createdLte: "2025-01-31T23:59:59Z"
    }
    paginate: { limit: 20, offset: 0 }
  ) {
    transactions {
      record_id
      transaction_type
      amount
      description
      status
      created_at
    }
    totalCount
    hasNextPage
  }
}
```

***

### 示例 3：仅购买且包含余额

**查询**:

```graphql theme={null}
query GetPurchaseHistory {
  getTransactions(
    filter: {
      transactionType: ["GIFT_CARD_PURCHASE"]
      status: [SETTLED]
    }
    paginate: { limit: 20, offset: 0 }
  ) {
    transactions {
      record_id
      reference_id
      amount
      description
      source
      destination
      cashback
      cashback_rate
      cash_balance_available_balance
      seat_balance_available_balance
      created_at
    }
    totalCount
    hasNextPage
  }
}
```

**响应**:

```json theme={null}
{
  "data": {
    "getTransactions": {
      "transactions": [
        {
          "record_id": "550e8400-e29b-41d4-a716-446655440000",
          "reference_id": "1000123",
          "amount": 50.00,
          "description": "Gift card purchase at Amazon",
          "source": "Visa ****1234",
          "destination": "Amazon",
          "cashback": 2.50,
          "cashback_rate": 5.0,
          "cash_balance_available_balance": 102.50,
          "seat_balance_available_balance": 25.00,
          "created_at": "2025-01-15T14:30:00Z"
        }
      ],
      "totalCount": 1,
      "hasNextPage": false
    }
  }
}
```

***

### 示例 4：高返现交易

**查询**:

```graphql theme={null}
query GetHighCashbackTransactions {
  getTransactions(
    filter: {
      cashbackPercentageGte: 5.0
      status: [SETTLED]
    }
    paginate: { limit: 10, offset: 0 }
  ) {
    transactions {
      record_id
      transaction_type
      amount
      description
      cashback
      cashback_rate
      status
      created_at
    }
    totalCount
  }
}
```

***

### 示例 5：金额区间筛选

**查询**:

```graphql theme={null}
query GetMediumTransactions {
  getTransactions(
    filter: {
      amountGte: 50.00
      amountLte: 200.00
      status: [SETTLED]
    }
    paginate: { limit: 20, offset: 0 }
  ) {
    transactions {
      record_id
      amount
      transaction_type
      description
      created_at
    }
    totalCount
    hasNextPage
  }
}
```

***

### 示例 6：虚拟卡交易

**查询**:

```graphql theme={null}
query GetVirtualCardTransactions {
  getTransactions(
    filter: {
      virtualCardProgram: ["LITHIC", "MARQETA"]
    }
    paginate: { limit: 20, offset: 0 }
  ) {
    transactions {
      record_id
      amount
      description
      virtual_card_program
      merchant_id
      status
      created_at
    }
    totalCount
  }
}
```

***

### 示例 7：分页示例

**查询 - 获取第一页并检查是否有更多**:

```graphql theme={null}
query GetFirstPage {
  getTransactions(paginate: { limit: 20, offset: 0 }) {
    transactions {
      record_id
      amount
      transaction_type
    }
    totalCount
    hasNextPage
  }
}
```

**响应显示 hasNextPage=true**:

```json theme={null}
{
  "data": {
    "getTransactions": {
      "transactions": [...],
      "totalCount": 150,
      "hasNextPage": true
    }
  }
}
```

**查询 - 获取第二页**:

```graphql theme={null}
query GetSecondPage {
  getTransactions(paginate: { limit: 20, offset: 20 }) {
    transactions {
      record_id
      amount
      transaction_type
    }
    totalCount
    hasNextPage
  }
}
```

***

## 错误处理

### 常见错误

#### 缺失或无效令牌

```json theme={null}
{
  "errors": [
    {
      "message": "Authentication required",
      "extensions": {
        "code": "UNAUTHENTICATED"
      }
    }
  ]
}
```

**HTTP 状态**: 401 Unauthorized

***

#### 权限不足

```json theme={null}
{
  "errors": [
    {
      "message": "Insufficient permissions: LIST_PAYMENT and LIST_PURCHASES scopes required",
      "extensions": {
        "code": "FORBIDDEN",
        "requiredScopes": ["LIST_PAYMENT", "LIST_PURCHASES"]
      }
    }
  ]
}
```

**HTTP 状态**: 403 Forbidden

***

#### 无效的筛选参数

```json theme={null}
{
  "errors": [
    {
      "message": "Invalid date format for createdGte",
      "extensions": {
        "code": "BAD_USER_INPUT"
      }
    }
  ]
}
```

**HTTP 状态**: 400 Bad Request

***

#### 超出速率限制

```json theme={null}
{
  "errors": [
    {
      "message": "Rate limit exceeded. Please try again later.",
      "extensions": {
        "code": "RATE_LIMITED",
        "retryAfter": 60
      }
    }
  ]
}
```

**HTTP 状态**: 429 Too Many Requests

***

## 最佳实践

### 1. 有效使用分页

始终检查 `hasNextPage` 以判断是否存在更多结果：

```javascript theme={null}
async function fetchAllTransactions() {
  const allTransactions = [];
  let offset = 0;
  const limit = 20;
  
  while (true) {
    const result = await getTransactions({ 
      paginate: { limit, offset } 
    });
    
    allTransactions.push(...result.transactions);
    
    if (!result.hasNextPage) break;
    offset += limit;
  }
  
  return allTransactions;
}
```

### 2. 仅请求所需字段

仅指定你需要的字段以减少响应大小：

```graphql theme={null}
# Good - minimal fields
getTransactions {
  transactions {
    record_id
    amount
    transaction_type
    created_at
  }
  totalCount
  hasNextPage
}

# Less efficient - requesting all 40+ fields
getTransactions {
  transactions {
    record_id
    transaction_type
    amount
    ... (all fields)
  }
}
```

### 3. 对历史查询使用日期筛选

在查询较早的交易时，务必使用日期筛选：

```graphql theme={null}
# Good
filter: {
  createdGte: "2024-01-01T00:00:00Z"
  createdLte: "2024-12-31T23:59:59Z"
}
```

### 4. 缓存已结算交易

`status: SETTLED` 的交易是不可变的，可以进行缓存：

```javascript theme={null}
// Example caching strategy
const cacheKey = `transactions:${accountId}:${createdGte}:${createdLte}`;
let result = cache.get(cacheKey);

if (!result) {
  result = await getTransactions({
    filter: { status: ['SETTLED'], createdGte, createdLte }
  });
  cache.set(cacheKey, result, '1 hour');
}
```

### 5. 高效组合筛选

使用范围筛选先收窄结果，再应用其他筛选：

```graphql theme={null}
# Efficient - date range first
filter: {
  createdGte: "2025-01-01T00:00:00Z"
  createdLte: "2025-01-31T23:59:59Z"
  transactionType: ["GIFT_CARD_PURCHASE"]
  amountGte: 50.00
}
```

***

## 速率限制

| 资源       | 限额  | 时间窗  |
| -------- | --- | ---- |
| 每用户查询数   | 100 | 1 分钟 |
| 每 IP 查询数 | 300 | 1 分钟 |

**响应头**:

* `X-RateLimit-Limit` - 允许的最大请求数
* `X-RateLimit-Remaining` - 当前窗口剩余请求数
* `X-RateLimit-Reset` - 速率限制重置时间（Unix 时间戳）

***

## 代码示例

### JavaScript/TypeScript

```typescript theme={null}
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';

const client = new ApolloClient({
  uri: 'https://api.fluz.app/graphql',
  cache: new InMemoryCache(),
  headers: {
    authorization: `Bearer ${accessToken}`,
  },
});

const GET_TRANSACTIONS = gql`
  query GetTransactions($filter: TransactionFilterInput, $paginate: OffsetInput) {
    getTransactions(filter: $filter, paginate: $paginate) {
      transactions {
        record_id
        transaction_type
        amount
        description
        status
        cashback
        created_at
      }
      totalCount
      hasNextPage
    }
  }
`;

async function fetchTransactions() {
  const { data } = await client.query({
    query: GET_TRANSACTIONS,
    variables: {
      filter: {
        status: ['SETTLED'],
        createdGte: '2025-01-01T00:00:00Z',
      },
      paginate: {
        limit: 20,
        offset: 0,
      },
    },
  });
  
  return data.getTransactions;
}
```

***

### Python

```python theme={null}
import requests

def get_transactions(access_token, created_gte=None, created_lte=None, limit=20, offset=0):
    url = "https://api.fluz.app/graphql"
    
    query = """
        query GetTransactions($filter: TransactionFilterInput, $paginate: OffsetInput) {
            getTransactions(filter: $filter, paginate: $paginate) {
                transactions {
                    record_id
                    transaction_type
                    amount
                    description
                    status
                    cashback
                    created_at
                }
                totalCount
                hasNextPage
            }
        }
    """
    
    variables = {
        "filter": {},
        "paginate": {
            "limit": limit,
            "offset": offset
        }
    }
    
    if created_gte:
        variables["filter"]["createdGte"] = created_gte
    if created_lte:
        variables["filter"]["createdLte"] = created_lte
    
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    }
    
    response = requests.post(
        url,
        json={"query": query, "variables": variables},
        headers=headers
    )
    
    return response.json()["data"]["getTransactions"]

# Usage
result = get_transactions(
    access_token="your_token_here",
    created_gte="2025-01-01T00:00:00Z",
    limit=20
)

print(f"Found {result['totalCount']} transactions")
print(f"Has more pages: {result['hasNextPage']}")
```

***

### cURL

```bash theme={null}
curl -X POST https://api.fluz.app/graphql \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query GetTransactions($filter: TransactionFilterInput, $paginate: OffsetInput) { getTransactions(filter: $filter, paginate: $paginate) { transactions { record_id transaction_type amount description status cashback created_at } totalCount hasNextPage } }",
    "variables": {
      "filter": {
        "status": ["SETTLED"],
        "createdGte": "2025-01-01T00:00:00Z"
      },
      "paginate": {
        "limit": 20,
        "offset": 0
      }
    }
  }'
```

***

## 常见问题

### 问：一次请求最多能获取多少笔交易？

答：每次请求的最大数量为 20 笔。使用 `hasNextPage` 字段实现分页。

### 问：交易历史能追溯到多久以前？

答：自账户创建以来的所有交易可无限期访问。

### 问：是否包含待处理交易？

答：是，默认会包含待处理交易。若要排除，请筛选 `status: [SETTLED]`。

### 问：时间戳使用什么时区？

答：所有时间戳均为 UTC（ISO 8601 格式）。

### 问：我需要哪些权限范围（scopes）？

答：你需要同时具备 `LIST_PAYMENT` 和 `LIST_PURCHASES` 两个范围。

### 问：我可以按账户内的用户 ID 进行筛选吗？

答：不可以。该 API 始终返回你账户的所有交易，不支持用户级别筛选。

### 问：`amount` 与 `finalAmount` 筛选有何区别？

答：

* `amount` 筛选基础交易金额
* `finalAmount` 筛选 金额 + 手续费（向用户收取的总额）

### 问：如何按日期范围筛选？

答：使用创建时间的 `createdGte` 和 `createdLte`：

```graphql theme={null}
filter: {
  createdGte: "2025-01-01T00:00:00Z"
  createdLte: "2025-01-31T23:59:59Z"
}
```

***

## 支持

* **API 状态**: [https://status.fluz.app](https://status.fluz.app)
* **开发者门户**: [https://developers.fluz.app](https://developers.fluz.app)
* **支持邮箱**: [api-support@fluz.app](mailto:api-support@fluz.app)
* **Slack 社区**: [https://fluz-dev.slack.com](https://fluz-dev.slack.com)

***

## 变更日志

### v1.0.0（分支：13-fluz-15659-add-transactions-query-and-webhook-to-api）

* 首次发布 Transactions 查询 API
* 支持全面筛选（15+ 种筛选类型）
* 使用 `TransactionConnection` 响应类型的分页
* 交易记录中包含余额快照
* 需要 `LIST_PAYMENT` 和 `LIST_PURCHASES` 范围
* 仅账户级交易访问

***

需要帮助？请联系开发者支持团队：[api-support@fluz.app](mailto:api-support@fluz.app) 或访问我们的[开发者门户](https://developers.fluz.app)。
