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

# Get a user's earnings

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

Module: Earnings · operationId: `getUserEarnings` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/get-user-earnings

Returns what a user has earned in commissions and overrides, split into pending, paid, projected and clawbacks, plus a per-pay-period breakdown. It mirrors the Earnings page in Sequifi. The buckets overlap with the reserve: `paid` includes money held in the user's reserve, so never add the reserve `balance` to `paid`.

**What happens:**

- Figures come from the earning lines themselves, so a user has numbers as soon as they earn, before any payroll is built.
- `pending`: earned and not paid yet, excluding lines on cancelled accounts and lines an admin marked Do Not Pay. Lines already on a finalized but unpaid payroll are included.
- `paid`: every line marked paid, including lines on accounts cancelled later and lines diverted into the user's reserve (Reserve Balances add-on). Reserve-held dollars therefore appear both here and in GET /v1/users/{id}/reserve.
- `projected`: forecast for milestones that have not happened yet, on accounts that are not cancelled.
- `clawbacks`: the lifetime total of every clawback on record, as a negative amount. It includes clawbacks already deducted from earlier paychecks or settled against the reserve.
- `totals.unpaid` is `pending + projected + clawbacks`, and `totals.lifetime` adds `paid` (it matches the total on the Earnings page). Because `clawbacks` is lifetime, `unpaid` is not a balance still owed.
- Commission figures count only sales where the user is a closer or setter. Overrides count every override paid to the user, since they are earned on other users' sales.
- Lines marked Do Not Pay are in no bucket.
- `accounts` counts distinct sales, not lines.

**Filtering and paging:**

- `pay_period_from` and `pay_period_to` filter on each line's own pay period, inclusive: the period starts on or after `pay_period_from` and ends on or before `pay_period_to`.
- With either filter, `projected` and `clawbacks` are returned as `0`. To see clawbacks for a period, call GET /v1/users/{id}/earnings/items with the same filter and `pay_status=clawed_back`.
- `pay_periods` lists periods newest first, commissions and overrides merged, each split into `pending` and `paid`. `periods` caps the list (default 12, maximum 60), and `pay_periods_truncated` is `true` when more exist.
- `pay_periods` does not add up to the buckets: its `pending` includes lines on cancelled accounts, it skips lines with no pay period, and it has no projections or clawbacks.

**Formats:**

- Amounts are JSON numbers in dollars, rounded to cents. Clawbacks are negative.
- Pay period dates are `YYYY-MM-DD`.

**Errors:**

- `400 Invalid user id`, `400 Invalid query parameter(s)`, `400 pay_period_from must be in YYYY-MM-DD format` (or `pay_period_to`), `400 pay_period_from must be on or before pay_period_to`, `400 periods must be an integer between 1 and 60`.
- `404 User not found`.

**Common mistakes:**

- Adding the reserve `balance` to `paid`. They share the same dollars.
- Treating `totals.unpaid` as money owed.
- Safe practice: for money waiting to be paid, sum `pending` and `approved` lines from GET /v1/users/{id}/earnings/items. For money paid to the user's paychecks, sum its `paid` lines (which exclude reserve). For money held, read `balance` from GET /v1/users/{id}/reserve.

**Related:**

- GET /v1/users/{id}/earnings/items lists the lines behind these totals.
- GET /v1/users/{id}/reserve shows money held back from payroll.
- GET /v1/users/{id}/commissions shows the rates behind the earnings.

## Path parameters

- `id` (integer, **required**): User id from GET /v1/users. Minimum: 1. Example: `4821`.

## Query parameters

- `pay_period_from` (string (date)): Only lines whose pay period starts on or after this date. Format `YYYY-MM-DD`. Sets `projected` and `clawbacks` to 0. Example: `2026-08-01`.
- `pay_period_to` (string (date)): Only lines whose pay period ends on or before this date. Format `YYYY-MM-DD`. Sets `projected` and `clawbacks` to 0. Example: `2026-08-31`.
- `periods` (integer): How many pay periods to return in `pay_periods`. Default: `12`. Minimum: 1. Maximum: 60. Example: `12`.

## Example request

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

## Responses

### 200: The user's earnings

- `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): `pay_period_from`, `pay_period_to` and `periods` as applied, or null.
  - `commissions` (object): Commission buckets `pending`, `paid`, `projected` and `clawbacks`, each `{accounts, amount}`.
  - `overrides` (object): Override buckets `pending`, `paid`, `projected` and `clawbacks`, each `{accounts, amount}`.
  - `totals` (object): Commissions plus overrides.
    - `pending` (number): Earned, not paid, not cancelled, not Do Not Pay.
    - `paid` (number): Marked paid. Includes reserve-held money.
    - `projected` (number): Forecast. `0` under a pay-period filter.
    - `clawbacks` (number): Lifetime clawbacks, negative. `0` under a pay-period filter.
    - `unpaid` (number): `pending + projected + clawbacks`. Not a balance owed.
    - `lifetime` (number): `pending + paid + projected + clawbacks`.
  - `pay_periods` (array of object): Per-pay-period breakdown, newest first.
    - `pay_period_from` (string (date)): Period start.
    - `pay_period_to` (string (date)): Period end.
    - `commission` (number): Commission in the period, pending plus paid.
    - `override` (number): Overrides in the period, pending plus paid.
    - `pending` (number): Not yet paid. Includes lines on cancelled accounts.
    - `paid` (number): Paid.
    - `amount` (number): Everything in the period.
  - `pay_periods_truncated` (boolean): `true` when more periods exist than `periods` allowed.

```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,
    "commissions": {
      "pending": {
        "accounts": 3,
        "amount": 1500
      },
      "paid": {
        "accounts": 8,
        "amount": 6200
      },
      "projected": {
        "accounts": 2,
        "amount": 900
      },
      "clawbacks": {
        "accounts": 1,
        "amount": -400
      }
    },
    "overrides": {
      "pending": {
        "accounts": 2,
        "amount": 120
      },
      "paid": {
        "accounts": 5,
        "amount": 480
      },
      "projected": {
        "accounts": 0,
        "amount": 0
      },
      "clawbacks": {
        "accounts": 0,
        "amount": 0
      }
    },
    "totals": {
      "pending": 1620,
      "paid": 6680,
      "projected": 900,
      "clawbacks": -400,
      "unpaid": 2120,
      "lifetime": 8800
    },
    "pay_periods": [
      {
        "pay_period_from": "2026-09-14",
        "pay_period_to": "2026-09-20",
        "commission": 1500,
        "override": 120,
        "pending": 1620,
        "paid": 0,
        "amount": 1620
      },
      {
        "pay_period_from": "2026-09-07",
        "pay_period_to": "2026-09-13",
        "commission": 2100,
        "override": 180,
        "pending": 0,
        "paid": 2280,
        "amount": 2280
      }
    ],
    "pay_periods_truncated": false
  }
}
```

### 400: Invalid user id, query parameter, date, range, or periods value

Example (invalid_params): Unknown query parameter

```json
{
  "status": 400,
  "message": "Invalid query parameter(s)",
  "data": {
    "invalid_params": [
      "foo"
    ],
    "allowed_params": [
      "pay_period_from",
      "pay_period_to",
      "periods"
    ]
  }
}
```

### 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": {}
}
```
