# Attribution groups API

## GET /api/v1/admin/attribution-groups

`GET /api/v1/admin/attribution-groups` · operation `getAttributionGroups`

Global quotas:read. Reads the effective governed attribution rule set (the latest immutable version), its source (yaml or console), its fingerprint and whether it differs from the current YAML base. The YAML base is adopted as a new version when none exists or when the effective version came from YAML and the YAML changed; a console version is never replaced by a YAML edit. Requires attribution_groups and PostgreSQL; no-store.

**Authentication:** `adminSession`

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Effective rule set | `application/json`: [AttributionRuleSetSnapshot](/docs/api/schemas/a/#attributionrulesetsnapshot) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |


## PUT /api/v1/admin/attribution-groups

`PUT /api/v1/admin/attribution-groups` · operation `publishAttributionGroups`

Publish a complete rule set as the next immutable version. Live global administrator, quotas:manage, same origin and CSRF required; compare-and-set on the current version; audited as attribution_groups.publish. A version cannot drop a group that an enabled quota policy targets. Rules match only server-owned identity (authenticated team, key and canonical model alias); client labels never choose a group. Already recorded requests keep the version they were attributed under.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `version` (integer (int64), required, min 0)
  - `policy` ([AttributionGroupPolicy](/docs/api/schemas/a/#attributiongrouppolicy), required)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Effective rule set after commit | `application/json`: [AttributionRuleSetSnapshot](/docs/api/schemas/a/#attributionrulesetsnapshot) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | version_conflict, group_in_use (a budgeted group would be dropped) or quota_base_mismatch | — |
| `422` | Rule set violates bounds or references | — |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |


## DELETE /api/v1/admin/attribution-groups

`DELETE /api/v1/admin/attribution-groups` · operation `revertAttributionGroups`

Publish the current YAML base again as the next immutable version (source yaml). Same rights, CSRF, compare-and-set, audit (attribution_groups.revert) and reference checks as PUT. History is kept.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `version` (integer (int64), required, min 0)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Effective rule set after commit | `application/json`: [AttributionRuleSetSnapshot](/docs/api/schemas/a/#attributionrulesetsnapshot) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `409` | version_conflict or group_in_use | — |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |


## GET /api/v1/admin/attribution-groups/versions

`GET /api/v1/admin/attribution-groups/versions` · operation `listAttributionGroupVersions`

Global quotas:read. Without version, lists immutable rule set versions newest first (counts, source, actor, request ID, time). With version, returns that version's complete body. No-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `limit` | query | integer, default `50`, min 1, max 200 | Most versions listed, newest first, 1-200 (50 by default). |
| `version` | query | integer (int64), min 1 |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | History page or one version | `application/json`: object or [AttributionRuleSet](/docs/api/schemas/a/#attributionruleset) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled or version not found | — |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object or [AttributionRuleSet](/docs/api/schemas/a/#attributionruleset)
  - One of (1): object
    - `items` (array of [AttributionRuleSetSummary](/docs/api/schemas/a/#attributionrulesetsummary), required)
  - One of (2): [AttributionRuleSet](/docs/api/schemas/a/#attributionruleset)


## GET /api/v1/admin/attribution-groups/report

`GET /api/v1/admin/attribution-groups/report` · operation `getAttributionGroupReport`

Global quotas:read. Aggregates usage events by captured team, group and source over at most 366 days (default the last 30), after the optional team filter. Coverage counts every selected event by rule, team default, unmatched and not evaluated (recorded without attribution), with the rule set versions seen. estimated_usd sums only known valuations, priced from the price book with discounts and margins frozen in each event; partial, unknown and not valued events are counted, never treated as zero. With budget_charge_reports each group adds budget_charge (what its budgets took at the approved rates) and the CSV adds budget_charged_usd, budget_charged and budget_held. format=csv returns the same rows plus a coverage line. No-store.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `from` | query | string (date-time) |  |
| `to` | query | string (date-time) |  |
| `team` | query | string, pattern `^[a-z][a-z0-9_-]{1,63}$` |  |
| `format` | query | string, one of `"json"`, `"csv"` |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Report | `application/json`: [AttributionReport](/docs/api/schemas/a/#attributionreport)<br/>`text/csv`: string |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |

