# query

URL: /business/nouns/collection/query · Id: `verb:Collection.query` · Call: `await $.Collection.query({ … })` (SDK) or the `do` tool at `https://api.sb/mcp`. Inputs says what to pass, Outputs what returns, When it waits who approves.

> Query reads any Nouns the caller’s Permissions allow, by SQL or a Relationship path, across every System in one call.

Query reads any [Nouns](/business/nouns/noun) the caller’s [Permissions](/business/nouns/permission) allow, by SQL or a [Relationship](/business/nouns/relationship) path, across every [System](/business/nouns/system) in one call.

## Inputs
| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `query` | `text` | Yes | SQL, or a Relationship path such as `customer.subscriptions.invoices`. |
| `save` | `boolean` | No | True saves it as a Collection defined by the query. |

## Outputs
| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `rows` | `json` | Yes | The matching records. |
| `collection` | [Collection](/business/nouns/collection) | Yes | The Collection the query read. |

## Effects
- Emits [`Collection.queried`](/business/events/Collection.queried).
- Performed by the [Analyst](/agents/marketing/analyst).
- Two-way: it runs at once, in the `try`, `send` and `do` modes.

## Refuses when
| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | [Collection.query](/business/nouns/collection/query) |

## When it waits
| Gate | Default |
| --- | --- |
| Decision class | Low: two-way, nothing at stake |
| [Delay window](/systems/trust-and-governance/controls/one-way-windows) | None: it runs once review passes. |
| Limit | The call [Limit](/business/nouns/limit) of the [Permission](/business/nouns/permission) it runs under. |
| Over the Limit | It waits `pending` for an [Approval](/business/nouns/approval) from the [Founder](/agents/founding/founder). Approved, it runs; refused, it ends `refused` with [`limit-exceeded`](/code/api/errors/limit-exceeded); unanswered by its deadline, it ends `canceled`. |

## Example

**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' })"
  }
}
```

Guides that call it: [Which integrations do people want](/start/guides/which-integrations-do-people-want).