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

# List earning history

> List a customer's point earning history.

List a customer's point earning history. The `identifier` can be a Shopify customer ID or email.

## Query parameters

| Parameter        | Type    | Description                                                                                                            |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| `filter[status]` | string  | Filter by status: `pending`, `approved`, `rejected`                                                                    |
| `sort`           | string  | Sort field. Prefix with `-` for descending. Options: `created_at`, `points`, `points_given_at`. Default: `-created_at` |
| `page[number]`   | integer | Page number (default: `1`)                                                                                             |
| `page[size]`     | integer | Results per page (default: `20`, max: `100`)                                                                           |

## Response

## Errors

| Status | Scenario                                                              |
| ------ | --------------------------------------------------------------------- |
| `404`  | Customer not found                                                    |
| `429`  | [Rate limit](/api-reference/rate-limits) exceeded (6 requests/second) |

<RequestExample>
  ```bash cURL theme={null}
  curl --request GET \
    --url https://api.mageloyalty.com/v1/customers/6789012345/earning-history \
    --header 'Authorization: <api-key>'
  ```

  ```bash cURL (filter + sort + page) theme={null}
  curl --request GET \
    --url 'https://api.mageloyalty.com/v1/customers/6789012345/earning-history?filter[status]=approved&sort=-points_given_at&page[number]=1&page[size]=20' \
    --header 'Authorization: <api-key>'
  ```

  ```javascript Node theme={null}
  const params = new URLSearchParams({
    "filter[status]": "approved",
    sort: "-points_given_at",
    "page[number]": "1",
    "page[size]": "20",
  });

  const response = await fetch(
    `https://api.mageloyalty.com/v1/customers/6789012345/earning-history?${params}`,
    {
      method: "GET",
      headers: { Authorization: "<api-key>" },
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      "https://api.mageloyalty.com/v1/customers/6789012345/earning-history",
      headers={"Authorization": "<api-key>"},
      params={
          "filter[status]": "approved",
          "sort": "-points_given_at",
          "page[number]": 1,
          "page[size]": 20,
      },
  )

  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $query = http_build_query([
      "filter[status]" => "approved",
      "sort" => "-points_given_at",
      "page[number]" => 1,
      "page[size]" => 20,
  ]);
  $ch = curl_init("https://api.mageloyalty.com/v1/customers/6789012345/earning-history?$query");
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => ["Authorization: <api-key>"],
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "data": [
      {
        "type": "earning_history_entry",
        "id": "entry_abc",
        "attributes": {
          "earning_rule_id": "rule_abc",
          "action": "purchase",
          "points": 150,
          "base_points": 100,
          "points_multiplier": 1.5,
          "status": "approved",
          "order_id": "5678901234",
          "order_number": "#1042",
          "points_due_at": null,
          "points_given_at": "2024-06-01T12:05:00.000Z",
          "points_expiry_at": null,
          "created_at": "2024-06-01T12:00:00.000Z",
          "updated_at": "2024-06-01T12:05:00.000Z"
        }
      }
    ],
    "meta": {
      "total": 12,
      "page": 1,
      "per_page": 20,
      "total_pages": 1
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "errors": [
      {
        "status": "404",
        "title": "Not Found",
        "detail": "Customer '6789012345' not found"
      }
    ]
  }
  ```
</ResponseExample>
