# Sales API

Every sales call: what to send, what comes back, and copy-ready examples.

## List sales

`GET /sales` (scope: sales:read)

```bash
curl "https://api.usetotems.com/v1/sales?status=unknown&limit=50" \
  -H "Authorization: Bearer $TOTEMS_KEY"
```

```json
{
  "data": [
    {
      "id": "6f20adad-3b47-4c0e-9a55-1f2e3d4c5b6a",
      "occurred_at": "2026-11-28T11:34:55.767Z",
      "person_id": "6f20cc9c-3b47-4c0e-9a55-1f2e3d4c5b6a",
      "person_name": "Reese Demo",
      "amount_cents": 4913,
      "net_cents": 3276,
      "currency": "USD",
      "home_net_cents": 3276,
      "label": "Template pack",
      "source": "stripe",
      "first_touch": {
        "at": "2026-09-16T22:51:46.218Z",
        "title": "How I plan my week",
        "channel": "youtube",
        "content_id": "6f20eb8b-3b47-4c0e-9a55-1f2e3d4c5b6a"
      },
      "last_touch": {
        "at": "2026-11-25T17:34:55.767Z",
        "title": "Five pricing mistakes",
        "channel": "youtube",
        "content_id": "6f210a7a-3b47-4c0e-9a55-1f2e3d4c5b6a"
      },
      "match_method": "visitor",
      "status": "ok"
    }
  ],
  "next_cursor": "MjAyNi0xMS0yOCAwNDoxNDoyNS44MDI3NjcrMDB8ZTQ2MzVmYzktOTFhZS00MDNkLTllMTMtMDFjN2JlNWYxNGE3",
  "request_id": "req_..."
}
```

## Add a trusted sale

`POST /sales` (scope: sales:write)

```bash
curl -X POST "https://api.usetotems.com/v1/sales" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "external_id": "order-1001",
    "amount_cents": 200000,
    "currency": "USD",
    "email": "alex@example.com",
    "occurred_at": "2026-11-09T15:00:00Z",
    "label": "Coaching plan"
  }'
```

```json
{
  "data": {
    "created": true,
    "id": "2a8faca9-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "occurred_at": "2026-12-03T23:43:22.494Z",
    "amount_cents": 200000,
    "refunded_cents": 0,
    "disputed_cents": 0,
    "net_cents": 200000,
    "currency": "USD",
    "home_net_cents": 200000,
    "home_currency": "USD",
    "label": "Coaching plan",
    "source": "api",
    "status": "ok",
    "is_test": true,
    "manual_content_id": null,
    "match": {
      "method": "email",
      "person_id": "2a847cfa-7c15-4e2b-8d44-5b6a7c8d9e0f"
    },
    "credit": {
      "first": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "last": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "even": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "position": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "decay": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ]
    },
    "refunds": [],
    "proof": [
      "$2,000 came from api on 3 Dec 2026, 23:43.",
      "We matched the sale with the same email.",
      "We found no tracked click in the 90 days before the sale. The credit is Unknown."
    ],
    "window_days": 90
  },
  "request_id": "req_..."
}
```

## Sale and proof

`GET /sales/{id}` (scope: sales:read)

```bash
curl "https://api.usetotems.com/v1/sales/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a" \
  -H "Authorization: Bearer $TOTEMS_KEY"
```

```json
{
  "data": {
    "id": "6f20adad-3b47-4c0e-9a55-1f2e3d4c5b6a",
    "occurred_at": "2026-11-28T11:34:55.767Z",
    "amount_cents": 4913,
    "refunded_cents": 1637,
    "disputed_cents": 0,
    "net_cents": 3276,
    "currency": "USD",
    "home_net_cents": 3276,
    "home_currency": "USD",
    "label": "Template pack",
    "source": "stripe",
    "status": "ok",
    "is_test": false,
    "manual_content_id": null,
    "match": {
      "method": "visitor",
      "person_id": "6f20cc9c-3b47-4c0e-9a55-1f2e3d4c5b6a"
    },
    "credit": {
      "first": [
        {
          "content_id": "6f20eb8b-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "How I plan my week",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 3276
        }
      ],
      "last": [
        {
          "content_id": "6f210a7a-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "Five pricing mistakes",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 3276
        }
      ],
      "even": [
        {
          "content_id": "6f20eb8b-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "How I plan my week",
          "channel": "youtube",
          "share": 0.33333333,
          "amount_cents": 1092
        },
        {
          "content_id": "6f214858-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "Email that gets replies",
          "channel": "email",
          "share": 0.33333333,
          "amount_cents": 1092
        }
      ],
      "position": [
        {
          "content_id": "6f20eb8b-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "How I plan my week",
          "channel": "youtube",
          "share": 0.4,
          "amount_cents": 1311
        },
        {
          "content_id": "6f214858-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "Email that gets replies",
          "channel": "email",
          "share": 0.2,
          "amount_cents": 655
        }
      ],
      "decay": [
        {
          "content_id": "6f20eb8b-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "How I plan my week",
          "channel": "youtube",
          "share": 0.00055876,
          "amount_cents": 2
        },
        {
          "content_id": "6f214858-3b47-4c0e-9a55-1f2e3d4c5b6a",
          "title": "Email that gets replies",
          "channel": "email",
          "share": 0.43960005,
          "amount_cents": 1440
        }
      ]
    },
    "refunds": [
      {
        "id": "6f216747-3b47-4c0e-9a55-1f2e3d4c5b6a",
        "amount_cents": 1637,
        "reason": "Asked for a refund",
        "occurred_at": "2026-11-30T11:34:55.767Z"
      }
    ],
    "proof": [
      "$49.13 came from stripe on 28 Nov 2026, 06:34.",
      "We matched the sale with a browser id from your own site."
    ],
    "window_days": 90
  },
  "request_id": "req_..."
}
```

## Choose credit by hand

`PATCH /sales/{id}/credit` (scope: sales:write)

```bash
curl -X PATCH "https://api.usetotems.com/v1/sales/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/credit" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "content_id": "6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a",
    "reason": "Alex told us on the call"
  }'
```

```json
{
  "data": {
    "id": "2a8faca9-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "occurred_at": "2026-12-03T23:43:22.494Z",
    "amount_cents": 200000,
    "refunded_cents": 0,
    "disputed_cents": 0,
    "net_cents": 200000,
    "currency": "USD",
    "home_net_cents": 200000,
    "home_currency": "USD",
    "label": "Coaching plan",
    "source": "api",
    "status": "ok",
    "is_test": true,
    "manual_content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "match": {
      "method": "email",
      "person_id": "2a847cfa-7c15-4e2b-8d44-5b6a7c8d9e0f"
    },
    "credit": {
      "first": [
        {
          "content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "title": "How I plan my week (new cut)",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "last": [
        {
          "content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "title": "How I plan my week (new cut)",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "even": [
        {
          "content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "title": "How I plan my week (new cut)",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "position": [
        {
          "content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "title": "How I plan my week (new cut)",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "decay": [
        {
          "content_id": "2a6e1d9c-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "title": "How I plan my week (new cut)",
          "channel": "youtube",
          "share": 1,
          "amount_cents": 200000
        }
      ]
    },
    "refunds": [],
    "proof": [
      "$2,000 came from api on 3 Dec 2026, 23:43.",
      "We matched the sale with the same email.",
      "Someone on your team chose the credit by hand. The rules do not change it.",
      "A click shows part of the path. It does not prove one thing caused the sale."
    ],
    "window_days": 90
  },
  "request_id": "req_..."
}
```

## Go back to the rules

`DELETE /sales/{id}/credit` (scope: sales:write)

```bash
curl -X DELETE "https://api.usetotems.com/v1/sales/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/credit" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```json
{
  "data": {
    "id": "2a8faca9-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "occurred_at": "2026-12-03T23:43:22.494Z",
    "amount_cents": 200000,
    "refunded_cents": 0,
    "disputed_cents": 0,
    "net_cents": 200000,
    "currency": "USD",
    "home_net_cents": 200000,
    "home_currency": "USD",
    "label": "Coaching plan",
    "source": "api",
    "status": "ok",
    "is_test": true,
    "manual_content_id": null,
    "match": {
      "method": "email",
      "person_id": "2a847cfa-7c15-4e2b-8d44-5b6a7c8d9e0f"
    },
    "credit": {
      "first": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "last": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "even": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "position": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ],
      "decay": [
        {
          "content_id": null,
          "title": null,
          "channel": "unknown",
          "share": 1,
          "amount_cents": 200000
        }
      ]
    },
    "refunds": [],
    "proof": [
      "$2,000 came from api on 3 Dec 2026, 23:43.",
      "We matched the sale with the same email.",
      "We found no tracked click in the 90 days before the sale. The credit is Unknown."
    ],
    "window_days": 90
  },
  "request_id": "req_..."
}
```

## Add a refund

`POST /sales/{id}/refunds` (scope: sales:write)

```bash
curl -X POST "https://api.usetotems.com/v1/sales/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/refunds" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "external_id": "refund-1001",
    "amount_cents": 50000,
    "reason": "Left early"
  }'
```

```json
{
  "data": {
    "refund_id": "2a96110d-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "created": true,
    "sale": {
      "id": "2a8faca9-7c15-4e2b-8d44-5b6a7c8d9e0f",
      "occurred_at": "2026-12-03T23:43:22.494Z",
      "amount_cents": 200000,
      "refunded_cents": 50000,
      "disputed_cents": 0,
      "net_cents": 150000,
      "currency": "USD",
      "home_net_cents": 150000,
      "home_currency": "USD",
      "label": "Coaching plan",
      "source": "api",
      "status": "ok",
      "is_test": true,
      "manual_content_id": null,
      "match": {
        "method": "email",
        "person_id": "2a847cfa-7c15-4e2b-8d44-5b6a7c8d9e0f"
      },
      "credit": {
        "first": [
          {
            "content_id": null,
            "title": null,
            "channel": "unknown",
            "share": 1,
            "amount_cents": 150000
          }
        ],
        "last": [
          {
            "content_id": null,
            "title": null,
            "channel": "unknown",
            "share": 1,
            "amount_cents": 150000
          }
        ],
        "even": [
          {
            "content_id": null,
            "title": null,
            "channel": "unknown",
            "share": 1,
            "amount_cents": 150000
          }
        ],
        "position": [
          {
            "content_id": null,
            "title": null,
            "channel": "unknown",
            "share": 1,
            "amount_cents": 150000
          }
        ],
        "decay": [
          {
            "content_id": null,
            "title": null,
            "channel": "unknown",
            "share": 1,
            "amount_cents": 150000
          }
        ]
      },
      "refunds": [
        {
          "id": "2a96110d-7c15-4e2b-8d44-5b6a7c8d9e0f",
          "amount_cents": 50000,
          "reason": "Left early",
          "occurred_at": "2026-12-03T23:43:23.449Z"
        }
      ],
      "proof": [
        "$2,000 came from api on 3 Dec 2026, 23:43.",
        "We matched the sale with the same email.",
        "We found no tracked click in the 90 days before the sale. The credit is Unknown.",
        "$500 was refunded, so every touch lost the same share."
      ],
      "window_days": 90
    }
  },
  "request_id": "req_..."
}
```
