# Collection

URL: /business/nouns/collection · Id: `noun:collection`

> A Collection is a Thing with members, either listed one by one or defined by a saved query.

A Collection is a [Thing](/business/nouns/thing) with members, either listed one by one or defined by a saved query.

## Properties
| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `query` | `json` | No | The saved query that defines a dynamic Collection. |

<details>
<summary>Inherited from [Thing](/business/nouns/thing): 4 properties</summary>

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | The stable identifier, which never changes. |
| `type` | list of [Noun](/business/nouns/noun) | Yes | The Nouns this Thing is an instance of. |
| `state` | `string` | No | The current state in its lifecycle. |
| `outside` | `json` | No | The ids this Thing has in outside tools, one per Integration, so a re-run matches instead of duplicating. |

</details>

## Object
```json
{
  "$id": "https://api.sb/kilnbakery.com/collections/collection_1",
  "$type": "Collection",
  "id": "Example id",
  "type": [
    "noun_1"
  ],
  "state": "Example state",
  "outside": {},
  "query": {}
}
```

## Relationships
- <a id="rel-contains"></a>A Collection **contains** many [Things](/business/nouns/thing): Members are listed one by one or matched by the Collection’s saved query; a [Thing](/business/nouns/thing) can belong to many Collections. `contains`, inverse [`memberOf`](/business/nouns/thing#rel-member-of).

## Verbs
| Verb | Description | Subject | Event | Class |
| --- | --- | --- | --- | --- |
| [Collection.export](/business/nouns/collection/export) | Export writes a Collection’s records to a file or the Startup’s warehouse, once or on a schedule. | [Data Engineer](/agents/engineering/data-engineer) | [`Collection.exported`](/business/events/Collection.exported) | Two-way: `try`, `send`, `do` |
| [Collection.query](/business/nouns/collection/query) | Query reads any Nouns the caller’s Permissions allow, by SQL or a Relationship path, across every System in one call. | [Analyst](/agents/marketing/analyst) | [`Collection.queried`](/business/events/Collection.queried) | Two-way: `try`, `send`, `do` |
| <a id="create"></a>[Collection.create](/business/nouns/collection/create) | Creates a Collection. Inherited from [Noun](/business/nouns/noun). | None. | `Collection.created` | Two-way: `try`, `send`, `do` |
| <a id="get"></a>[Collection.get](/business/nouns/collection/get) | Returns one Collection by id. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="list"></a>[Collection.list](/business/nouns/collection/list) | Returns Collections, newest first, one page at a time. Inherited from [Noun](/business/nouns/noun). | None. | None. | Read: `try`, `do` |
| <a id="update"></a>[Collection.update](/business/nouns/collection/update) | Changes the given properties of a Collection. Inherited from [Noun](/business/nouns/noun). | None. | `Collection.updated` | Two-way: `try`, `send`, `do` |
| <a id="delete"></a>[Collection.delete](/business/nouns/collection/delete) | Deletes a Collection; its history is kept. Inherited from [Noun](/business/nouns/noun). | None. | `Collection.deleted` | One-way: `send`, `do` |

## Permissions
Which Access level may call each Verb. One-way Verbs wait their delay window.

| Operation | `owner` | `admin` | `member` | `viewer` |
| --- | --- | --- | --- | --- |
| `Collection.create` | Yes | Yes | Yes | No |
| `Collection.get` | Yes | Yes | Yes | Yes |
| `Collection.list` | Yes | Yes | Yes | Yes |
| `Collection.update` | Yes | Yes | Yes | No |
| `Collection.delete` | Yes | Yes | Yes | No |
| `Collection.export` | Yes | Yes | Yes | No |
| `Collection.query` | Yes | Yes | Yes | No |

## Call it

**Ask**

```text
Query the latest collection.
```

**API**

```bash
curl -X POST https://api.sb/tutorloop.com/collections/query \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"Example query"}'
```

```json
{
  "api": "https://api.sb/tutorloop.com",
  "rows": {},
  "collection": {
    "$id": "https://api.sb/tutorloop.com/collections/collection_1",
    "$type": "Collection",
    "id": "Example id",
    "type": [
      "noun_1"
    ]
  },
  "action": {
    "$id": "https://api.sb/tutorloop.com/actions/action_1",
    "operation": "Collection.query",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/tutorloop.com/actions/action_1"
  }
}
```

**SDK**

```ts
import { $ } from 'startup-builder'

const { rows, collection } = await $.Collection.query({ query: 'Example query' })
```

**CLI**

```bash
npx startup-builder do Collection.query --json '{"query":"Example query"}'
```

**MCP**

```json
{
  "name": "do",
  "arguments": {
    "code": "return await $.Collection.query({ query: 'Example query' })"
  }
}
```

## Example
The Collection "enterprise [Customers](/business/nouns/customer)" is a saved query for Customers with more than 50 seats. A new Customer at 51 seats joins it at once.