<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/billing/invoices/list-invoices -->

# List Invoices

Retrieve a paginated list of invoices with optional filtering and sorting.

<EndpointHeader verb="GET" path="/merchant/api/v1/invoices" />

## Request

### Headers

<ParamTable
  label="Header"
  rows={[
    { name: "Authorization", required: true, desc: "`Bearer {api_key}`" },
    { name: "X-Signature", required: true, desc: "HMAC-SHA256 signature" },
    { name: "X-Timestamp", required: true, desc: "ISO 8601 timestamp" },
    { name: "X-Secret-Salt", required: true, desc: "Secret salt for HMAC validation" },
    { name: "Content-Type", required: true, desc: "`application/json`" },
  ]}
/>

### Query Parameters

<ParamTable
  rows={[
    { name: "status", type: "string", desc: "Filter by status: `DRAFT`, `SENT`, `VIEWED`, `PARTIALLY_PAID`, `PAID`, `OVERDUE`, `CANCELLED`, `VOID`" },
    { name: "currency", type: "string", desc: "Filter by currency code" },
    { name: "customerId", type: "string", desc: "Filter by customer ID" },
    { name: "startDate", type: "string", desc: "Filter invoices issued on or after this date (ISO 8601)" },
    { name: "endDate", type: "string", desc: "Filter invoices issued on or before this date (ISO 8601)" },
    { name: "page", type: "number", desc: "Page number (default: `1`)" },
    { name: "limit", type: "number", desc: "Items per page (default: `20`, max: `100`)" },
    { name: "sortBy", type: "string", desc: "Sort field (default: `createdAt`)" },
    { name: "sortOrder", type: "string", desc: "Sort direction: `ASC` or `DESC` (default: `DESC`)" },
    { name: "searchTerm", type: "string", desc: "Search by invoice number or customer name" },
  ]}
/>

## Response

### Success (200 OK)

```json
{
  "success": true,
  "data": {
    "items": [
      {
        "invoiceId": "inv_a1b2c3d4e5f6g7h8",
        "invoiceNumber": "INV-2024-0001",
        "customerId": "cust_a1b2c3d4e5f6g7h8",
        "customerEmail": "john@example.com",
        "customerName": "John Doe",
        "currency": "USD",
        "status": "SENT",
        "issueDate": "2024-01-15T00:00:00.000Z",
        "dueDate": "2024-02-15T00:00:00.000Z",
        "totalAmount": 275.00,
        "amountPaid": 0,
        "amountDue": 275.00,
        "createdAt": "2024-01-15T10:30:00.000Z",
        "updatedAt": "2024-01-15T10:30:00.000Z"
      }
    ],
    "total": 1,
    "page": 1,
    "limit": 20,
    "totalPages": 1
  },
  "message": "Invoices retrieved successfully",
  "error": null,
  "meta": {
    "request_id": "req_xxxxx",
    "timestamp": "2024-01-15T10:30:00.000Z",
    "processing_time_ms": 40,
    "api_version": "v1",
    "endpoint": "GET /invoices",
    "user_type": "merchant"
  }
}
```

### Error Responses

<ErrorTable
  rows={[
    { code: "VALIDATION_ERROR", status: "400", message: "Invalid query parameters" },
    { code: "UNAUTHORIZED", status: "401", message: "Invalid API key" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X GET "https://api.zenpayz.com/merchant/api/v1/invoices?status=SENT&page=1&limit=20" \
  -H "Authorization: Bearer zp_test_xxxxx" \
  -H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
  -H "X-Signature: a1b2c3d4e5f6..." \
  -H "X-Secret-Salt: your_secret_salt" \
  -H "Content-Type: application/json"
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const params = new URLSearchParams({
  status: 'SENT',
  page: '1',
  limit: '20',
});

const response = await fetch(`https://api.zenpayz.com/merchant/api/v1/invoices?${params}`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'X-Timestamp': timestamp,
    'X-Signature': signature,
    'X-Secret-Salt': secretSalt,
    'Content-Type': 'application/json',
  },
});

const result = await response.json();
console.log(result.data.items); // Array of invoices
console.log(result.data.total); // Total count
```

  </TabItem>
  <TabItem value="sdk" label="SDK">

```javascript
const invoices = await zenpays.invoices.list({
  status: 'SENT',
  page: 1,
  limit: 20,
});

console.log(invoices.items); // Array of invoices
console.log(invoices.total); // Total count
```

  </TabItem>
</Tabs>

</CodeRail>

## Related Endpoints

- [Create Invoice](/docs/rest-api/endpoints/billing/invoices/create-invoice)
- [Get Invoice](/docs/rest-api/endpoints/billing/invoices/get-invoice)
- [Invoice Analytics](/docs/rest-api/endpoints/billing/invoices/invoice-analytics)
