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

# Filtering

> Advanced filtering and search for transactions

## Overview

Master advanced filtering techniques to find exactly the transactions you need. This guide covers all available filters, search patterns, and optimization strategies.

**What you'll learn:**

* Filter by multiple criteria
* Combine filters effectively
* Search strategies
* Performance optimization
* Common filtering patterns

***

## Available Filters

All filter parameters for transaction queries:

| Filter      | Type   | Description        | Example                      |
| ----------- | ------ | ------------------ | ---------------------------- |
| `status`    | string | Transaction status | SUCCESS, PENDING, FAILED     |
| `type`      | string | Transaction type   | DEBIT, CREDIT, PEER-TRANSFER |
| `currency`  | string | Currency code      | NGN, USD, SOL, ETH           |
| `minAmount` | number | Minimum amount     | 1000                         |
| `maxAmount` | number | Maximum amount     | 50000                        |
| `startDate` | string | Start date         | 2024-02-01                   |
| `endDate`   | string | End date           | 2024-02-29                   |
| `sortBy`    | string | Sort field         | createdAt, amount, updatedAt |
| `sortOrder` | string | Sort direction     | asc, desc                    |
| `page`      | number | Page number        | 1                            |
| `limit`     | number | Items per page     | 20                           |

***

## Filter by Status

Get transactions by status.

<CodeGroup>
  ```javascript Node.js theme={null}
  import MoneiSDK from 'monei-sdk';

  const monei = new MoneiSDK({
    apiKey: process.env.MONEI_API_KEY,
  });

  // Get successful transactions
  const successful = await monei.transactions.getAll({
    status: 'SUCCESS',
    limit: 20
  });

  console.log('Successful:', successful.pagination.total);

  // Get pending transactions
  const pending = await monei.transactions.getAll({
    status: 'PENDING',
    limit: 20
  });

  console.log('Pending:', pending.pagination.total);

  // Get failed transactions
  const failed = await monei.transactions.getAll({
    status: 'FAILED',
    limit: 20
  });

  console.log('Failed:', failed.pagination.total);

  // Get completed transactions
  const completed = await monei.transactions.getAll({
    status: 'COMPLETED',
    limit: 20
  });

  console.log('Completed:', completed.pagination.total);
  ```

  ```python Python theme={null}
  from monei import MoneiClient

  monei = MoneiClient(
      api_key=os.getenv('MONEI_API_KEY')
  )

  # Successful
  successful = monei.transactions.get_all(
      status='SUCCESS',
      limit=20
  )
  print(f'Successful: {successful.pagination.total}')

  # Pending
  pending = monei.transactions.get_all(
      status='PENDING',
      limit=20
  )
  print(f'Pending: {pending.pagination.total}')

  # Failed
  failed = monei.transactions.get_all(
      status='FAILED',
      limit=20
  )
  print(f'Failed: {failed.pagination.total}')
  ```
</CodeGroup>

***

## Filter by Type

Get transactions by type (DEBIT, CREDIT, etc.).

<CodeGroup>
  ```javascript Node.js theme={null}
  // Money out (debits)
  const debits = await monei.transactions.getAll({
    type: 'DEBIT',
    limit: 20
  });

  console.log('Debits (Money Out):', debits.pagination.total);
  debits.transactions.forEach(tx => {
    console.log(`  - ₦${tx.amount} to ${tx.narration}`);
  });

  // Money in (credits)
  const credits = await monei.transactions.getAll({
    type: 'CREDIT',
    limit: 20
  });

  console.log('\nCredits (Money In):', credits.pagination.total);
  credits.transactions.forEach(tx => {
    console.log(`  + ₦${tx.amount} from ${tx.narration}`);
  });

  // Peer transfers
  const p2p = await monei.transactions.getAll({
    type: 'PEER-TRANSFER',
    limit: 20
  });

  console.log('\nP2P Transfers:', p2p.pagination.total);
  ```

  ```python Python theme={null}
  # Debits
  debits = monei.transactions.get_all(
      type='DEBIT',
      limit=20
  )
  print(f'Debits: {debits.pagination.total}')

  # Credits
  credits = monei.transactions.get_all(
      type='CREDIT',
      limit=20
  )
  print(f'Credits: {credits.pagination.total}')

  # P2P
  p2p = monei.transactions.get_all(
      type='PEER-TRANSFER',
      limit=20
  )
  print(f'P2P: {p2p.pagination.total}')
  ```
</CodeGroup>

***

## Filter by Currency

Get transactions for specific currencies.

<CodeGroup>
  ```javascript Node.js theme={null}
  // Naira transactions
  const ngnTxns = await monei.transactions.getAll({
    currency: 'NGN',
    limit: 20
  });

  console.log('NGN Transactions:', ngnTxns.pagination.total);

  // USD transactions
  const usdTxns = await monei.transactions.getAll({
    currency: 'USD',
    limit: 20
  });

  console.log('USD Transactions:', usdTxns.pagination.total);

  // SOL transactions
  const solTxns = await monei.transactions.getAll({
    currency: 'SOL',
    limit: 20
  });

  console.log('SOL Transactions:', solTxns.pagination.total);

  // ETH transactions
  const ethTxns = await monei.transactions.getAll({
    currency: 'ETH',
    limit: 20
  });

  console.log('ETH Transactions:', ethTxns.pagination.total);
  ```

  ```python Python theme={null}
  # NGN
  ngn_txns = monei.transactions.get_all(
      currency='NGN',
      limit=20
  )
  print(f'NGN: {ngn_txns.pagination.total}')

  # USD
  usd_txns = monei.transactions.get_all(
      currency='USD',
      limit=20
  )
  print(f'USD: {usd_txns.pagination.total}')

  # SOL
  sol_txns = monei.transactions.get_all(
      currency='SOL',
      limit=20
  )
  print(f'SOL: {sol_txns.pagination.total}')
  ```
</CodeGroup>

***

## Filter by Amount Range

Get transactions within specific amount ranges.

<CodeGroup>
  ```javascript Node.js theme={null}
  // Small transactions (under ₦1,000)
  const small = await monei.transactions.getAll({
    maxAmount: 1000,
    currency: 'NGN',
    limit: 20
  });

  console.log('Small (<₦1K):', small.pagination.total);

  // Medium transactions (₦1,000 - ₦10,000)
  const medium = await monei.transactions.getAll({
    minAmount: 1000,
    maxAmount: 10000,
    currency: 'NGN',
    limit: 20
  });

  console.log('Medium (₦1K-₦10K):', medium.pagination.total);

  // Large transactions (₦10,000 - ₦100,000)
  const large = await monei.transactions.getAll({
    minAmount: 10000,
    maxAmount: 100000,
    currency: 'NGN',
    limit: 20
  });

  console.log('Large (₦10K-₦100K):', large.pagination.total);

  // Very large transactions (>₦100,000)
  const veryLarge = await monei.transactions.getAll({
    minAmount: 100000,
    currency: 'NGN',
    limit: 20
  });

  console.log('Very Large (>₦100K):', veryLarge.pagination.total);
  ```

  ```python Python theme={null}
  # Small
  small = monei.transactions.get_all(
      max_amount=1000,
      currency='NGN',
      limit=20
  )
  print(f'Small: {small.pagination.total}')

  # Medium
  medium = monei.transactions.get_all(
      min_amount=1000,
      max_amount=10000,
      currency='NGN',
      limit=20
  )
  print(f'Medium: {medium.pagination.total}')

  # Large
  large = monei.transactions.get_all(
      min_amount=10000,
      max_amount=100000,
      currency='NGN',
      limit=20
  )
  print(f'Large: {large.pagination.total}')
  ```
</CodeGroup>

***

## Filter by Date Range

Get transactions within specific time periods.

<CodeGroup>
  ```javascript Node.js theme={null}
  // Today
  const today = new Date().toISOString().split('T')[0];
  const todayTxns = await monei.transactions.getAll({
    startDate: today,
    endDate: today,
    limit: 100
  });

  console.log('Today:', todayTxns.pagination.total);

  // This week
  const thisWeekStart = new Date();
  thisWeekStart.setDate(thisWeekStart.getDate() - 7);
  const thisWeek = await monei.transactions.getAll({
    startDate: thisWeekStart.toISOString().split('T')[0],
    endDate: today,
    limit: 100
  });

  console.log('This Week:', thisWeek.pagination.total);

  // This month
  const thisMonthStart = new Date();
  thisMonthStart.setDate(1);
  const thisMonth = await monei.transactions.getAll({
    startDate: thisMonthStart.toISOString().split('T')[0],
    endDate: today,
    limit: 100
  });

  console.log('This Month:', thisMonth.pagination.total);

  // Last month
  const lastMonthStart = new Date();
  lastMonthStart.setMonth(lastMonthStart.getMonth() - 1);
  lastMonthStart.setDate(1);
  const lastMonthEnd = new Date();
  lastMonthEnd.setDate(0);
  const lastMonth = await monei.transactions.getAll({
    startDate: lastMonthStart.toISOString().split('T')[0],
    endDate: lastMonthEnd.toISOString().split('T')[0],
    limit: 100
  });

  console.log('Last Month:', lastMonth.pagination.total);

  // Custom range
  const custom = await monei.transactions.getAll({
    startDate: '2024-01-01',
    endDate: '2024-01-31',
    limit: 100
  });

  console.log('January 2024:', custom.pagination.total);
  ```

  ```python Python theme={null}
  from datetime import datetime, timedelta

  # Today
  today = datetime.now().strftime('%Y-%m-%d')
  today_txns = monei.transactions.get_all(
      start_date=today,
      end_date=today,
      limit=100
  )
  print(f'Today: {today_txns.pagination.total}')

  # This week
  week_ago = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')
  this_week = monei.transactions.get_all(
      start_date=week_ago,
      end_date=today,
      limit=100
  )
  print(f'This Week: {this_week.pagination.total}')

  # This month
  month_start = datetime.now().replace(day=1).strftime('%Y-%m-%d')
  this_month = monei.transactions.get_all(
      start_date=month_start,
      end_date=today,
      limit=100
  )
  print(f'This Month: {this_month.pagination.total}')

  # Custom range
  custom = monei.transactions.get_all(
      start_date='2024-01-01',
      end_date='2024-01-31',
      limit=100
  )
  print(f'January: {custom.pagination.total}')
  ```
</CodeGroup>

***

## Combine Multiple Filters

Combine filters for precise queries.

<CodeGroup>
  ```javascript Node.js theme={null}
  // Successful debits over ₦10,000 this month
  const results = await monei.transactions.getAll({
    type: 'DEBIT',
    status: 'SUCCESS',
    minAmount: 10000,
    currency: 'NGN',
    startDate: '2024-02-01',
    endDate: '2024-02-29',
    sortBy: 'amount',
    sortOrder: 'desc',
    limit: 50
  });

  console.log('Matching Transactions:', results.pagination.total);

  // Display results
  results.transactions.forEach(tx => {
    console.log(`₦${tx.amount.toLocaleString()} - ${tx.narration}`);
    console.log(`  Date: ${new Date(tx.createdAt).toLocaleDateString()}`);
    console.log(`  Ref: ${tx.reference}`);
    console.log('');
  });

  // Failed transactions this week
  const failed = await monei.transactions.getAll({
    status: 'FAILED',
    startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
    endDate: new Date().toISOString().split('T')[0],
    limit: 20
  });

  console.log('Failed This Week:', failed.pagination.total);

  // Credits (money in) over ₦5,000
  const largeCredits = await monei.transactions.getAll({
    type: 'CREDIT',
    minAmount: 5000,
    currency: 'NGN',
    sortBy: 'createdAt',
    sortOrder: 'desc',
    limit: 20
  });

  console.log('Large Credits:', largeCredits.pagination.total);
  ```

  ```python Python theme={null}
  # Complex filter
  results = monei.transactions.get_all(
      type='DEBIT',
      status='SUCCESS',
      min_amount=10000,
      currency='NGN',
      start_date='2024-02-01',
      end_date='2024-02-29',
      sort_by='amount',
      sort_order='desc',
      limit=50
  )

  print(f'Matching: {results.pagination.total}')

  for tx in results.transactions:
      print(f'₦{tx.amount:,} - {tx.narration}')
      print(f'  Date: {tx.created_at}')
      print()

  # Failed this week
  from datetime import datetime, timedelta
  week_ago = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')

  failed = monei.transactions.get_all(
      status='FAILED',
      start_date=week_ago,
      end_date=datetime.now().strftime('%Y-%m-%d'),
      limit=20
  )

  print(f'Failed: {failed.pagination.total}')
  ```
</CodeGroup>

***

## Sorting

Sort transactions by different fields.

<CodeGroup>
  ```javascript Node.js theme={null}
  // Sort by date (newest first)
  const newest = await monei.transactions.getAll({
    sortBy: 'createdAt',
    sortOrder: 'desc',
    limit: 20
  });

  // Sort by date (oldest first)
  const oldest = await monei.transactions.getAll({
    sortBy: 'createdAt',
    sortOrder: 'asc',
    limit: 20
  });

  // Sort by amount (highest first)
  const highestAmount = await monei.transactions.getAll({
    sortBy: 'amount',
    sortOrder: 'desc',
    limit: 20
  });

  // Sort by amount (lowest first)
  const lowestAmount = await monei.transactions.getAll({
    sortBy: 'amount',
    sortOrder: 'asc',
    limit: 20
  });

  // Sort by last updated
  const recentlyUpdated = await monei.transactions.getAll({
    sortBy: 'updatedAt',
    sortOrder: 'desc',
    limit: 20
  });
  ```

  ```python Python theme={null}
  # Newest first
  newest = monei.transactions.get_all(
      sort_by='createdAt',
      sort_order='desc',
      limit=20
  )

  # Oldest first
  oldest = monei.transactions.get_all(
      sort_by='createdAt',
      sort_order='asc',
      limit=20
  )

  # Highest amount
  highest = monei.transactions.get_all(
      sort_by='amount',
      sort_order='desc',
      limit=20
  )

  # Lowest amount
  lowest = monei.transactions.get_all(
      sort_by='amount',
      sort_order='asc',
      limit=20
  )
  ```
</CodeGroup>

***

## Common Filtering Patterns

<Tabs>
  <Tab title="Monthly Report">
    ```javascript theme={null}
    // Get all transactions for a specific month
    async function getMonthlyReport(year, month) {
      const startDate = `${year}-${String(month).padStart(2, '0')}-01`;
      const lastDay = new Date(year, month, 0).getDate();
      const endDate = `${year}-${String(month).padStart(2, '0')}-${lastDay}`;
      
      const txns = await monei.transactions.getAll({
        startDate: startDate,
        endDate: endDate,
        limit: 1000
      });
      
      return txns;
    }

    // Usage
    const feb2024 = await getMonthlyReport(2024, 2);
    console.log('February 2024:', feb2024.pagination.total);
    ```
  </Tab>

  <Tab title="Failed Transactions">
    ```javascript theme={null}
    // Get all failed transactions to review
    async function getFailedTransactions() {
      const failed = await monei.transactions.getAll({
        status: 'FAILED',
        sortBy: 'createdAt',
        sortOrder: 'desc',
        limit: 100
      });
      
      console.log('Failed Transactions:', failed.pagination.total);
      
      failed.transactions.forEach(tx => {
        console.log(`${tx.reference}: ₦${tx.amount}`);
        console.log(`  Reason: ${tx.failureReason || 'Unknown'}`);
      });
      
      return failed;
    }

    await getFailedTransactions();
    ```
  </Tab>

  <Tab title="Large Transactions">
    ```javascript theme={null}
    // Get transactions over a certain threshold
    async function getLargeTransactions(threshold = 50000) {
      const large = await monei.transactions.getAll({
        minAmount: threshold,
        currency: 'NGN',
        sortBy: 'amount',
        sortOrder: 'desc',
        limit: 100
      });
      
      console.log(`Transactions Over ₦${threshold}:`, large.pagination.total);
      
      return large;
    }

    await getLargeTransactions(100000);
    ```
  </Tab>

  <Tab title="Pending Review">
    ```javascript theme={null}
    // Get all pending transactions
    async function getPendingTransactions() {
      const pending = await monei.transactions.getAll({
        status: 'PENDING',
        sortBy: 'createdAt',
        sortOrder: 'asc',
        limit: 100
      });
      
      console.log('Pending Transactions:', pending.pagination.total);
      
      // Group by age
      const now = Date.now();
      const byAge = {
        recent: [],      // < 1 hour
        moderate: [],    // 1-24 hours
        old: []          // > 24 hours
      };
      
      pending.transactions.forEach(tx => {
        const age = now - new Date(tx.createdAt).getTime();
        const hours = age / (1000 * 60 * 60);
        
        if (hours < 1) {
          byAge.recent.push(tx);
        } else if (hours < 24) {
          byAge.moderate.push(tx);
        } else {
          byAge.old.push(tx);
        }
      });
      
      console.log('Recent (<1h):', byAge.recent.length);
      console.log('Moderate (1-24h):', byAge.moderate.length);
      console.log('Old (>24h):', byAge.old.length);
      
      return byAge;
    }

    await getPendingTransactions();
    ```
  </Tab>
</Tabs>

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Specific Filters" icon="crosshairs">
    Use specific filters to reduce response size
  </Card>

  <Card title="Date Ranges" icon="calendar-range">
    Always use date ranges for large datasets
  </Card>

  <Card title="Limit Results" icon="list-ol">
    Use appropriate page limits (max 100)
  </Card>

  <Card title="Cache Results" icon="database">
    Cache frequently accessed filter results
  </Card>

  <Card title="Sort Wisely" icon="arrow-down-short-wide">
    Sort by indexed fields (createdAt, amount)
  </Card>

  <Card title="Pagination" icon="angles-right">
    Always implement pagination for UX
  </Card>
</CardGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Management" icon="list" href="/transactions/management">
    Learn transaction management basics
  </Card>

  <Card title="Webhooks" icon="webhook" href="/security/webhooks">
    Set up real-time transaction notifications
  </Card>

  <Card title="Analytics" icon="chart-line" href="/transactions/management#transaction-analytics">
    Analyze transaction patterns
  </Card>

  <Card title="Export" icon="download" href="/transactions/management#export-transactions">
    Export transaction data
  </Card>
</CardGroup>
