---
title: "ResourceShark API: Reports"
description: "Get totals, with the ResourceShark API."
url: "https://agentpost.tools/docs/resourceshark/reference/reports"
kind: reference
---

# Reports

Read balance totals and sum movements by reason over a period.

Paths are relative to `https://api.agentpost.tools/v1/resources`. [Who may call](/docs/resourceshark/reference.md#who-may-call) explains each credential.

## Get totals

`GET /reports/totals`

Sums for each resource matched by a resource ID, a tag, or `attribute.<name>` parameters, including archived resources. Each row gives its balance over its scopes and, for a period from `from` to `to`, its movements summed by reason. `groupBy` breaks the totals down by an attribute of the supply entries on a resource that keeps its supply apart, and `holderRef` totals one holder’s scopes. A write that lands while the read runs may or may not be counted.

-   **Who may call:** Your server, with your project’s secret key.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.reports.totals(query)`

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resourceId` | `string` | No | 1–256 characters. |
| `tag` | `string` | No | 1–200 characters. |
| `from` | `string` | No | An ISO 8601 date and time. |
| `to` | `string` | No | An ISO 8601 date and time. |
| `groupBy` | `string` | No | 1–64 characters. |
| `holderRef` | `string` | No | 1–256 characters. |

### Response

`200 OK`, with [`TotalsReport`](/docs/resourceshark/reference/reports.md#the-totalsreport-object).

### Errors

-   [`invalid_request`](/docs/resourceshark/errors.md#invalid_request) (400)

Any operation can also answer with the codes [Conventions](/docs/resourceshark/reference.md#conventions) lists.

```bash tab="curl"
curl 'https://api.agentpost.tools/v1/resources/reports/totals?resourceId=res_01M83PPH000000000000000003&holderRef=principal%3Aexternal%3Au_maya&from=2026-11-23T09%3A20%3A00.000Z&to=2026-11-23T09%3A55%3A00.000Z&groupBy=program' \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/resourceshark-sdk';

const client = createClient({ token: 'sk_test_…' });
const result = await client.reports.totals({
  resourceId: 'res_01M83PPH000000000000000003',
  holderRef: 'principal:external:u_maya',
  from: '2026-11-23T09:20:00.000Z',
  to: '2026-11-23T09:55:00.000Z',
  groupBy: 'program',
});
```

```json title="Response"
{
  "asOf": "2026-11-23T09:55:00.000Z",
  "from": "2026-11-23T09:20:00.000Z",
  "to": "2026-11-23T09:55:00.000Z",
  "groupBy": "program",
  "holderRef": "principal:external:u_maya",
  "resources": [
    {
      "resourceId": "res_01M83PPH000000000000000003",
      "key": "tasting-credits",
      "name": "Prepaid tasting credits",
      "unit": {
        "code": "credit",
        "singular": "credit",
        "plural": "credits",
        "precision": 0
      },
      "balance": {
        "onHand": 8,
        "held": 0,
        "available": 8
      },
      "movements": {
        "add": 12,
        "use": -3,
        "settle": 1,
        "reversal": -2
      },
      "groups": [
        {
          "value": "tasting-club",
          "balance": {
            "onHand": 8,
            "held": 0,
            "available": 8
          },
          "movements": {
            "add": 12,
            "use": -3,
            "settle": 1,
            "reversal": -2
          }
        }
      ]
    }
  ]
}
```

## The TotalsReport object

Sums for each selected resource.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `asOf` | `string` | Always | When the totals were read. A balance counts what had expired by then; a write that landed while the read ran may or may not be counted. |
| `from` | `string` | When set | The period, when one was asked for. `from` is in it and `to` is not. |
| `to` | `string` | When set | An ISO 8601 date and time. |
| `groupBy` | `string` | When set |  |
| `holderRef` | `string` | When set | Your app’s name for the holder, such as `principal:external:u_maya`. |
| `resources` | [`ResourceTotals`](/docs/resourceshark/reference/reports.md#the-resourcetotals-object) array | Always | The resources the selection matched, in the order they were created. |

```json title="The TotalsReport object"
{
  "asOf": "2026-11-23T09:55:00.000Z",
  "from": "2026-11-23T09:20:00.000Z",
  "to": "2026-11-23T09:55:00.000Z",
  "groupBy": "program",
  "holderRef": "principal:external:u_maya",
  "resources": [
    {
      "resourceId": "res_01M83PPH000000000000000003",
      "key": "tasting-credits",
      "name": "Prepaid tasting credits",
      "unit": {
        "code": "credit",
        "singular": "credit",
        "plural": "credits",
        "precision": 0
      },
      "balance": {
        "onHand": 8,
        "held": 0,
        "available": 8
      },
      "movements": {
        "add": 12,
        "use": -3,
        "settle": 1,
        "reversal": -2
      },
      "groups": [
        {
          "value": "tasting-club",
          "balance": {
            "onHand": 8,
            "held": 0,
            "available": 8
          },
          "movements": {
            "add": 12,
            "use": -3,
            "settle": 1,
            "reversal": -2
          }
        }
      ]
    }
  ]
}
```

## The ResourceTotals object

One resource’s totals.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `resourceId` | `string` | Always | Resource ID, `res_…`. |
| `key` | `string` | Always |  |
| `name` | `string` | Always |  |
| `unit` | [`Unit`](/docs/resourceshark/reference/reports.md#the-unit-object) | Always |  |
| `balance` | [`TotalsBalance`](/docs/resourceshark/reference/reports.md#the-totalsbalance-object) or `null` | Always | The resource’s balance over its scopes, or one holder’s. Null on a resource counted in buckets: it has a balance for each bucket of time, and buckets of different times are never added together. |
| `movements` | `object` | When set | When a period was asked for: the resource’s movements in it, by reason. Each value is a `number`. |
| `groups` | [`TotalsGroup`](/docs/resourceshark/reference/reports.md#the-totalsgroup-object) array or `null` | When set | When `groupBy` was asked for: the totals for each value of that attribute on the resource’s supply entries, by value and the entries without it last. A unit counts in the group of the entry it sits on, and a movement in the groups of the entries it drew from or added to, so the groups add up to the resource’s totals. What a balance owes, and what holds hold beyond its entries, sit on no entry and count in the null group, and so does what is available on a balance that has either. Null on a resource that keeps one running balance or counts in buckets: it keeps no supply entries apart, so there is nothing to group by. |

```json title="The ResourceTotals object"
{
  "resourceId": "res_01M83PPH000000000000000003",
  "key": "tasting-credits",
  "name": "Prepaid tasting credits",
  "unit": {
    "code": "credit",
    "singular": "credit",
    "plural": "credits",
    "precision": 0
  },
  "balance": {
    "onHand": 8,
    "held": 0,
    "available": 8
  },
  "movements": {
    "add": 12,
    "use": -3,
    "settle": 1,
    "reversal": -2
  },
  "groups": [
    {
      "value": "tasting-club",
      "balance": {
        "onHand": 8,
        "held": 0,
        "available": 8
      },
      "movements": {
        "add": 12,
        "use": -3,
        "settle": 1,
        "reversal": -2
      }
    }
  ]
}
```

## The Unit object

A resource’s base unit, with its labels and its precision: the number of decimal places one unit of `Quantity` stands for.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `code` | `string` | Always |  |
| `singular` | `string` | Always |  |
| `plural` | `string` | Always |  |
| `precision` | `number` | Always |  |

```json title="The Unit object"
{
  "code": "g",
  "singular": "gram",
  "plural": "grams",
  "precision": 0
}
```

## The TotalsBalance object

A balance summed over scopes, each scope counted as a balance read counts it: an expired hold holds nothing, and supply past its expiry is not on hand.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `onHand` | `number` | Always | An integer in the resource’s base unit at its precision, as money is in cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A quantity with a fraction is refused with `invalid_quantity`. |
| `held` | `number` | Always | An integer in the resource’s base unit at its precision, as money is in cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A quantity with a fraction is refused with `invalid_quantity`. |
| `available` | `number` | Always | An integer in the resource’s base unit at its precision, as money is in cents: grams at precision 0, meters at precision 2, so 1 is 1 cm. A quantity with a fraction is refused with `invalid_quantity`. |

```json title="The TotalsBalance object"
{
  "onHand": 8,
  "held": 0,
  "available": 8
}
```

## The TotalsGroup object

The totals of one value of the grouping attribute, or of the entries without it.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `value` | `string` or `null` | Always | The attribute’s value on these entries, or null for the entries that don’t carry it. |
| `balance` | [`TotalsBalance`](/docs/resourceshark/reference/reports.md#the-totalsbalance-object) | Always | What these entries have, as the resource’s balance counts it. |
| `movements` | `object` | When set | When a period was asked for: what movements in it changed on these entries, by reason. Each value is a `number`. |

```json title="The TotalsGroup object"
{
  "value": "tasting-club",
  "balance": {
    "onHand": 8,
    "held": 0,
    "available": 8
  },
  "movements": {
    "add": 12,
    "use": -3,
    "settle": 1,
    "reversal": -2
  }
}
```
