<!-- Generated by scripts/build-docs.js. Edit docs/swagger.yaml or docs/guides/, then run `npm run docs:build`. -->

# List a user's earning lines

`GET https://marketplace-api.sequifi.com/v1/users/{id}/earnings/items`

Module: Earnings · operationId: `listUserEarningItems` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/list-user-earning-items

Returns the lines behind GET /v1/users/{id}/earnings, one per commission milestone, override, projection or clawback, each with a `pay_status` that says where the money is now. Unlike the summary, this splits reserve-held money out of `paid` into `reserved`.

**What happens:**

- A sale usually produces one line per milestone, plus override lines for the user's managers. Group by `pid` for a per-sale view.
- `pay_status` values:
  - `projected`: forecast; the milestone has not happened yet. No pay period.
  - `pending`: earned, not on a finalized payroll yet.
  - `approved`: on a payroll an admin finalized, not paid yet.
  - `paid`: paid on a paycheck. `pay_date` is set.
  - `reserved`: diverted into the user's reserve instead of a paycheck. See GET /v1/users/{id}/reserve.
  - `do_not_pay`: withheld by an admin and not paid on this run.
  - `cancelled`: unpaid line on a cancelled account.
  - `clawed_back`: money taken back after a cancellation, as a negative amount. Includes clawbacks already deducted on past paychecks.
- Scoping matches the summary: commission lines count only sales where the user is a closer or setter; override lines count every override paid to the user, and `override_from_user_id` is the user whose sale earned it.
- `summary` gives lines, accounts and amount for every status over the filtered set, before paging.
- Tie-out to GET /v1/users/{id}/earnings with no filters: its `pending` equals `pending` + `approved` here, and its `paid` equals `paid` + `reserved` here. `do_not_pay` and `cancelled` lines are in no summary bucket. With a pay-period filter the two do not tie out, because the summary zeroes clawbacks and this endpoint does not.

**Filtering and paging:**

- Filters combine with AND. `pay_status` takes a comma-separated list and matches any of them.
- `pay_period_from` and `pay_period_to` filter on the line's pay period. Lines with no pay period, such as projections, drop out.
- `date_from` and `date_to` filter on the sale date (`customer_signoff`). All date filters are inclusive.
- `page` defaults to 1. `per_page` defaults to 50, maximum 5000. A rep's whole list usually fits in one call at `per_page=5000`, which is much faster than paging: every call does the same work regardless of page size.
- Sorted newest first by pay period, then milestone date, then sale date.

**Formats:**

- Amounts are JSON numbers in dollars, rounded to cents. Clawbacks are negative.
- Dates are `YYYY-MM-DD`.
- `(source, id)` is the unique row key; `id` alone repeats across sources. Treat `source` as an opaque label.
- `product_name` is the product the sale was sold under, as the app names it, and `product_code` is its code. A sale whose product was retired and moved to the Default product reports the original product in both. `product_name` is null when the sale has no product.
- `payroll_id` is the pay stub the line belongs to, or null. Use it with GET /v1/payroll-history/{id} or GET /v1/payroll/{id}.

**Errors:**

- `400 Invalid user id`, `400 Invalid query parameter(s)`, `400 pay_status must be one or more of: ...`, `400 category must be one of: commission, override`, `400 <field> must be in YYYY-MM-DD format`, `400 pay_period_from must be on or before pay_period_to` (or `date_from`), `400 page must be a positive integer`, `400 per_page must be an integer between 1 and 5000`.
- `404 User not found`.

**Related:**

- GET /v1/users/{id}/earnings returns the bucket totals.
- GET /v1/payroll-history/{id}/line-items itemizes the stub a line was paid on.
- GET /v1/users/{id}/reserve explains `reserved` lines.

## Path parameters

- `id` (integer, **required**): User id. Look it up by email with GET /v1/users?email=. Minimum: 1. Example: `4821`.

## Query parameters

- `pay_status` (string): Comma-separated pay statuses: `projected`, `pending`, `approved`, `paid`, `reserved`, `do_not_pay`, `cancelled`, `clawed_back`. Example: `pending,approved,paid`.
- `category` (string): `commission` or `override`. One of: `commission`, `override`.
- `pid` (string): Only lines for this sale id.
- `pay_period_from` (string (date)): Only lines whose pay period starts on or after this date. Format `YYYY-MM-DD`. Example: `2026-08-01`.
- `pay_period_to` (string (date)): Only lines whose pay period ends on or before this date. Format `YYYY-MM-DD`. Example: `2026-08-31`.
- `date_from` (string (date)): Only lines on sales dated on or after this date. Format `YYYY-MM-DD`.
- `date_to` (string (date)): Only lines on sales dated on or before this date. Format `YYYY-MM-DD`.
- `page` (integer): Page number. Default: `1`. Minimum: 1.
- `per_page` (integer): Lines per page. Default: `50`. Minimum: 1. Maximum: 5000.

## Example request

```bash
curl -X GET "https://marketplace-api.sequifi.com/v1/users/4821/earnings/items" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN"
```

## Responses

### 200: The user's earning lines

- `status` (integer): The HTTP status code, repeated. Example: `200`.
- `message` (string): Short text. Wording varies by endpoint; branch on the HTTP status, not on this text. Example: `success`.
- `data` (object)
  - `requestedBy` (string): Label of the API credential that made the call.
  - `user` (object): The user: `id`, `employee_id`, `first_name`, `last_name`, `position_id`, `position_name`.
  - `filters` (object, nullable): Filters as applied (`pay_status` as an array), or null.
  - `summary` (object): One entry per pay status, always all eight, each `{lines, accounts, amount}`, over the filtered set before paging.
  - `current_page` (integer): Page returned.
  - `per_page` (integer): Lines per page.
  - `total` (integer): Lines across all pages.
  - `last_page` (integer): Last page number. At least `1`.
  - `items` (array of object): The lines on this page.
    - `source` (string): Opaque label for the kind of line. Use with `id` as the row key.
    - `id` (integer): Line id. Unique only together with `source`.
    - `category` (string): Commission or override. One of: `commission`, `override`.
    - `pay_status` (string): Where the money is now. One of: `projected`, `pending`, `approved`, `paid`, `reserved`, `do_not_pay`, `cancelled`, `clawed_back`.
    - `amount` (number): Dollars. Negative for clawbacks.
    - `pid` (string): Sale id.
    - `customer_name` (string, nullable): Sale customer.
    - `product_code` (string, nullable): Product code on the sale.
    - `product_name` (string, nullable): Name of the product the sale was sold under (the original product if the sale was moved to the Default product).
    - `customer_signoff` (string, nullable): Sale date.
    - `date_cancelled` (string, nullable): Date the sale was cancelled, or null.
    - `milestone_name` (string, nullable): Milestone name.
    - `milestone_trigger` (string, nullable): What triggers the milestone.
    - `milestone_date` (string, nullable): Date the milestone was reached.
    - `override_type` (string, nullable): Override kind on override lines, for example `Direct`.
    - `override_from_user_id` (integer, nullable): User whose sale earned the override.
    - `pay_period_from` (string, nullable): Start of the pay period the line belongs to.
    - `pay_period_to` (string, nullable): End of that pay period.
    - `payroll_id` (integer, nullable): Pay stub id, or null.
    - `pay_date` (string, nullable): Date the line was paid. Set on paid lines and clawbacks.

```json
{
  "status": 200,
  "message": "success",
  "data": {
    "requestedBy": "acme",
    "user": {
      "id": 4821,
      "employee_id": "EMP-4821",
      "first_name": "Alex",
      "last_name": "Morgan",
      "position_id": 5,
      "position_name": "Closer"
    },
    "filters": null,
    "summary": {
      "projected": {
        "lines": 0,
        "accounts": 0,
        "amount": 0
      },
      "pending": {
        "lines": 0,
        "accounts": 0,
        "amount": 0
      },
      "approved": {
        "lines": 1,
        "accounts": 1,
        "amount": 500
      },
      "paid": {
        "lines": 1,
        "accounts": 1,
        "amount": 120
      },
      "reserved": {
        "lines": 0,
        "accounts": 0,
        "amount": 0
      },
      "do_not_pay": {
        "lines": 0,
        "accounts": 0,
        "amount": 0
      },
      "cancelled": {
        "lines": 0,
        "accounts": 0,
        "amount": 0
      },
      "clawed_back": {
        "lines": 1,
        "accounts": 1,
        "amount": -400
      }
    },
    "current_page": 1,
    "per_page": 50,
    "total": 3,
    "last_page": 1,
    "items": [
      {
        "source": "user_commission",
        "id": 90211,
        "category": "commission",
        "pay_status": "approved",
        "amount": 500,
        "pid": "SALE-10482",
        "customer_name": "Riley Chen",
        "product_code": "SOLAR",
        "product_name": "Solar 300",
        "customer_signoff": "2026-08-02",
        "date_cancelled": null,
        "milestone_name": "M1",
        "milestone_trigger": "Install",
        "milestone_date": "2026-09-10",
        "override_type": null,
        "override_from_user_id": null,
        "pay_period_from": "2026-09-14",
        "pay_period_to": "2026-09-20",
        "payroll_id": 5521,
        "pay_date": null
      },
      {
        "source": "user_overrides",
        "id": 3310,
        "category": "override",
        "pay_status": "paid",
        "amount": 120,
        "pid": "SALE-10391",
        "customer_name": "Sam Patel",
        "product_code": "SOLAR",
        "product_name": "Solar 300",
        "customer_signoff": "2026-07-01",
        "date_cancelled": null,
        "milestone_name": null,
        "milestone_trigger": null,
        "milestone_date": null,
        "override_type": "Direct",
        "override_from_user_id": 4877,
        "pay_period_from": "2026-07-20",
        "pay_period_to": "2026-07-26",
        "payroll_id": 5107,
        "pay_date": "2026-08-01"
      },
      {
        "source": "clawback_settlements",
        "id": 712,
        "category": "commission",
        "pay_status": "clawed_back",
        "amount": -400,
        "pid": "SALE-10355",
        "customer_name": "Casey Brooks",
        "product_code": "SOLAR",
        "product_name": "Solar 300",
        "customer_signoff": "2026-06-11",
        "date_cancelled": "2026-07-02",
        "milestone_name": "M1",
        "milestone_trigger": "Install",
        "milestone_date": "2026-06-25",
        "override_type": null,
        "override_from_user_id": null,
        "pay_period_from": "2026-07-06",
        "pay_period_to": "2026-07-12",
        "payroll_id": 5033,
        "pay_date": "2026-07-17"
      }
    ]
  }
}
```

### 400: Invalid user id, query parameter, status, category, date, range, or paging value

Example (invalid_params): Unknown query parameter

```json
{
  "status": 400,
  "message": "Invalid query parameter(s)",
  "data": {
    "invalid_params": [
      "periods"
    ],
    "allowed_params": [
      "pay_status",
      "category",
      "pid",
      "pay_period_from",
      "pay_period_to",
      "date_from",
      "date_to",
      "page",
      "per_page"
    ]
  }
}
```

### 401: Missing, invalid or expired token. The gateway rejects the call before it reaches Sequifi, so the body has only a `message`.

```json
{
  "message": "Unauthorized"
}
```

### 404: User not found

```json
{
  "status": 404,
  "message": "User not found",
  "data": {}
}
```

### 500: Internal server error

```json
{
  "status": 500,
  "message": "Internal Server Error",
  "data": {}
}
```
