# Database

> A table of what you know about each contact. Ody adds and fills columns from conversations; you define your own, read and write values, find a row by phone number, and query everything with read-only SQL.

Source: https://dev.ody.co/api/data

The **Database** is a table with one row per contact. Its columns hold what the business knows about each contact: plan, budget, renewal date, "asked about pricing". You add columns, and Ody adds them too: when a contact says something in a call, a voicemail or a text that no column holds yet, Ody creates the column, fills it, and listens for the same thing in every later conversation. Each cell is filled by someone on the team, by this API, or by Ody.

Use this API to load what you already know about your customers, to read what Ody learned from conversations, and to answer questions about all of it with [SQL](https://dev.ody.co/api/data-sql).

> **Switched on per workspace:**
The Database is in beta and Ody turns it on for one workspace at a time. Until it is on for yours, every endpoint on this page returns `409 failed_precondition`. Write to [support@ody.co](mailto:support@ody.co) to ask for it.

> **SDK examples need v0.10.0:**
`ody.data` (TypeScript) and `client.data` (Python) are in v0.10.0 of the SDKs, which is not on npm or PyPI yet. With the published v0.9.0, use the cURL examples or any HTTP client.

## How the table works

| | |
|---|---|
| **Rows** | One per contact. Every contact has a row, including contacts with no values yet. A row is identified by the contact's `id`. |
| **Columns** | Added by your team, by this API, or by Ody. There is no maximum number of columns. Each has a `key` (`renewal_date`) that this API and SQL use. The key is made from the name the column was created with and never changes, so renaming a column in the app does not break your integration. |
| **Values** | Typed by the column: text, number, date, true / false, one choice, several choices. |
| **Who filled a cell** | Every filled cell records its `source`: `user`, `import`, `api`, `automation` or `ai`. |

**A value you write is yours.** A cell written through this API gets `source: "api"` and is locked: Ody does not replace it with something it hears in a later conversation. This is true when you clear a cell, too. Cells that nobody has written stay open for Ody to fill.

### Columns that Ody adds

Unless the workspace has turned it off, Ody adds a column when a contact says a kind of fact that no column holds. A remodeling company whose callers mention the type of project gets a **Project type** column without anyone creating it. These columns have `auto: true`.

What this means for an integration:

- **The column list changes on its own.** Read the columns with [`GET /data/columns`](#list-columns) or [`GET /data/schema`](#describe-the-table) when you need them. Do not keep a fixed list in your code.
- **Keys are still stable.** A column Ody added keeps its `key` for as long as it exists, like any other.
- **A column you create is never duplicated.** Ody compares names without regard to case, word order or small words: if you have **Project type**, Ody fills it and does not add "Type of project".
- **Deleting an `auto` column is remembered.** Ody does not add a column with that meaning again.
- **Some things are never added.** Ody does not create columns for card numbers, government IDs, passwords or health details, or for what the contact card already holds (name, phone number, e-mail, company, tags).

The workspace's owners and admins turn this on and off in the app, under **Database → AI → Add columns automatically**. There is no API for that switch.

### Scopes

| To | Scope |
|---|---|
| Read columns, rows, summaries, and run SQL | `contacts:read` |
| Write values, create a contact through upsert | `contacts:write` |
| Add, change or delete columns | `data:manage` |

Values are data about contacts, so they follow the contact scopes. Changing the shape of the table is a separate permission because deleting a column deletes every value in it.

### Test keys

`ody_test_…` keys read and write the same table as live keys. Nothing on this page sends a message or spends money, so there is nothing to simulate.

## The column object

- `id` *uuid* — Unique identifier. Accepted anywhere a `key` is.
- `key` *string* — The column's name in this API and in SQL. Lower case with underscores. Never changes.
- `name` *string* — The name people see in the app. Up to 60 characters.
- `description` *string* — What the column holds. When Ody fills the column, this is the instruction it follows. Up to 200 characters.
- `kind` *string* — `attribute`: a fact about the contact. `signal`: something the contact said or asked, counted per conversation.
- `type` *string* — `text`, `number`, `date`, `boolean`, `select` (one choice) or `multi_select` (several choices). A signal is always `boolean`.
- `options` *array of strings* — The choices of a `select` or `multi_select` column.
- `allowNewOptions` *boolean* — Whether Ody may add a choice it hears that is not in the list.
- `aiEnabled` *boolean* — Whether Ody fills this column from calls and texts.
- `fillRule` *string* — How Ody fills it. `latest`: a newer conversation replaces the value. `once`: the first value stays. `collect`: choices add up (`multi_select` only).
- `auto` *boolean* — `true` when Ody added the column itself, from something a contact said. See [Columns that Ody adds](#columns-that-ody-adds).
- `position` *integer* — Order in the table.
- `createdAt`, `updatedAt` *timestamp* — ISO 8601.

### Values by type

| `type` | Send | You get back |
|---|---|---|
| `text` | A string, up to 500 characters | The string |
| `number` | A number, or a string such as `"1,200"` | A number |
| `date` | `"YYYY-MM-DD"` (a full ISO timestamp is cut to its day) | `"YYYY-MM-DD"` |
| `boolean` | `true` / `false` (also `"yes"`, `"no"`) | `true` / `false` |
| `select` | One of the column's choices. Matching ignores case. | The choice as it is spelled in the column |
| `multi_select` | A list of choices | A list |
| signal | `true` / `false` | `true` / `false` |

`null` clears a value. An empty cell reads as `null`, except a signal column, which reads as `false`.

> **A choice that is not in the list is added:**
Writing `"Platinum"` to a `select` column whose choices are Free and Pro adds Platinum to the column, the same as when a person types a new choice in the app. Check the value against `options` first if you want to refuse unknown choices.

## The row object

- `contactId` *uuid* — The contact this row belongs to.
- `contact` *object* — The contact's own fields: `firstName`, `lastName`, `company`, `phone` (the first number), `email` (the first address), `tags`, `createdAt`, `lastContactedAt`. On workspaces where AI Contact is on, also the [card fields](#contact-card-fields). Read-only here; change them with the [Contacts API](https://dev.ody.co/api/contacts).
- `data` *object* — Every column by key, with its value.
- `cells` *object* — Only on single-row responses. The filled cells by column key, each with `value`, `source`, `locked`, `confidence`, `occurrences`, `lastObservedAt` and `updatedAt`.

The row object:

```json
{
  "contactId": "8b1d6f3e-2c4a-4e1b-9f0d-7a5c3e2b1a90",
  "contact": {
    "firstName": "Dana",
    "lastName": "Reyes",
    "company": "Brightline",
    "phone": "+15125550199",
    "email": "dana@brightline.com",
    "tags": ["vip"],
    "createdAt": "2026-10-14T18:02:11.000Z",
    "lastContactedAt": "2026-11-27T16:40:02.000Z"
  },
  "data": {
    "plan": "Pro",
    "seats": 12,
    "renewal_date": "2027-03-01",
    "newsletter": true,
    "interests": ["Voice", "AI"],
    "asked_about_pricing": true
  },
  "cells": {
    "plan": {
      "value": "Pro",
      "source": "api",
      "locked": true,
      "confidence": null,
      "occurrences": 0,
      "lastObservedAt": null,
      "updatedAt": "2026-11-29T15:02:11.000Z"
    },
    "asked_about_pricing": {
      "value": true,
      "source": "ai",
      "locked": false,
      "confidence": 0.92,
      "occurrences": 3,
      "lastObservedAt": "2026-11-27T16:40:02.000Z",
      "updatedAt": "2026-11-27T16:41:30.000Z"
    }
  }
}
```

For a signal column, `occurrences` is the number of conversations it came up in.

### Contact card fields

When **AI Contact** is on for a workspace, a contact carries more details than a name and a company: a job title, a postal address, and what the phone network says about the number. The Database shows each of them as a column, and the `contact` object of a row carries them too. A workspace without AI Contact gets none of these fields: they are absent from `contact`, and a filter or sort on one is rejected with `invalid_argument`.

| In `contact` | In a filter or sort | In SQL | What it holds |
|---|---|---|---|
| `jobTitle` | `contact.job_title` | `job_title` | Job title |
| `headline` | `contact.headline` | `headline` | A one-line professional headline |
| `website` | `contact.website` | `website` | The contact's website, as a bare domain |
| `linkedinUrl` | `contact.linkedin_url` | `linkedin_url` | LinkedIn profile URL |
| `companyDomain` | `contact.company_domain` | `company_domain` | The company's website, as a bare domain |
| `companyLinkedinUrl` | `contact.company_linkedin_url` | `company_linkedin_url` | The company's LinkedIn page |
| `secondaryPhone` | `contact.secondary_phone` | `secondary_phone` | A second phone number, E.164 |
| `addressStreet` | `contact.address_street` | `address_street` | Street address |
| `addressCity` | `contact.address_city` | `address_city` | City |
| `addressState` | `contact.address_state` | `address_state` | State or region |
| `addressPostalCode` | `contact.address_postal_code` | `address_postal_code` | ZIP or postal code |
| `addressCountry` | `contact.address_country` | `address_country` | Country, ISO 3166-1 alpha-2 when known (`US`) |
| `phoneLineType` | `contact.phone_line_type` | `phone_line_type` | `mobile`, `landline`, `voip`, `toll_free` or `unknown` |
| `phoneCarrier` | `contact.phone_carrier` | `phone_carrier` | Carrier of the contact's number |
| `callerIdName` | `contact.caller_id_name` | `caller_id_name` | Caller ID name published by the carrier |
| `aiNotes` | `contact.ai_notes` | `ai_notes` | Notes Ody took from conversations, one per line. Cannot be sorted on |

Each is text or `null`. They are the same fields the [Contacts API](https://dev.ody.co/api/contacts) returns, and that is where you change them: the Database API reads them and never writes them. Values are returned as stored. A state can be `TX` on one contact and `Texas` on another when a person typed one of them, so prefer `contains` or a list of spellings over an exact match on an address field.

Contacts in Texas on a mobile line:

```bash
curl -G https://api.ody.co/v1/api/data/rows \
  -H "Authorization: Bearer $ODY_API_KEY" \
  --data-urlencode 'filter=[{"column":"contact.address_state","op":"is","value":"TX"},{"column":"contact.phone_line_type","op":"is","value":"mobile"}]'
```

**`GET /v1/api/data/schema`**

### Describe the table

Returns the workspace's columns and the two tables that [`POST /data/query`](#query-with-sql) can read, with the exact SQL name and type of every column. Call this first when you write SQL, or give it to an AI assistant so it uses real column names.

**Scope:** `contacts:read`

**Returns** `{ columns: Column[], tables: Table[], limits }`. Each table column has `name`, `sql` (how to write it in a query), `type` and `description`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/schema \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
const { columns, tables } = await ody.data.schema();
```
Python:

```python
schema = client.data.schema()
```

Response:

```json
{
  "columns": [
    { "id": "5c1e…", "key": "plan", "name": "Plan", "kind": "attribute", "type": "select", "options": ["Free", "Pro"], "aiEnabled": false, "fillRule": "latest", "auto": false },
    { "id": "9a40…", "key": "project_type", "name": "Project type", "kind": "attribute", "type": "select", "options": ["Kitchen", "Bathroom"], "aiEnabled": true, "fillRule": "latest", "auto": true }
  ],
  "tables": [
    {
      "name": "contacts",
      "description": "One row per contact: the contact's own fields and one column per data column.",
      "columns": [
        { "name": "id", "sql": "id", "type": "id", "description": "The contact's id." },
        { "name": "name", "sql": "name", "type": "text", "description": "First and last name together." },
        { "name": "plan", "sql": "plan", "type": "text", "description": "Plan (one of: Free, Pro)", "columnKey": "plan" }
      ]
    },
    { "name": "observations", "description": "One row per thing Ody heard a contact say, with when and where.", "columns": [] }
  ],
  "limits": { "queryRows": 1000, "queryChars": 4000, "queryTimeoutMs": 5000, "pageSize": 100 }
}
```

**`GET /v1/api/data/columns`**

### List columns

Returns the columns in table order.

**Scope:** `contacts:read`

**Returns** `{ columns: Column[] }`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/columns \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
const columns = await ody.data.columns();
```
Python:

```python
columns = client.data.columns()
```

**`POST /v1/api/data/columns`**

### Add a column

Creates a column. `kind` and `type` cannot be changed afterwards. There is no maximum number of columns. A column you create has `auto: false`.

With `aiEnabled: true`, Ody starts filling the column from new calls and texts, using `description` as its instruction. A signal column that Ody fills needs a description. Ody does not fill columns for card numbers, government IDs, passwords or health details.

**Scope:** `data:manage`

**Body**

- `name` *string* **required** — Up to 60 characters. The `key` is made from it.
- `kind` *string* — `attribute` (default) or `signal`.
- `type` *string* — `text` (default), `number`, `date`, `boolean`, `select`, `multi_select`. Ignored for a signal.
- `description` *string* — Up to 200 characters.
- `options` *array of strings* — Up to 50 choices of up to 80 characters.
- `allowNewOptions` *boolean* — Default `false`.
- `aiEnabled` *boolean* — Default `false`.
- `fillRule` *string* — `latest` (default), `once` or `collect`.

**Returns** `201` with `{ column }`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/columns \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Plan",
    "type": "select",
    "options": ["Free", "Pro", "Enterprise"]
  }'
```
TypeScript:

```ts
const column = await ody.data.createColumn({
  name: "Plan",
  type: "select",
  options: ["Free", "Pro", "Enterprise"],
});
console.log(column.key); // "plan"
```
Python:

```python
column = client.data.create_column(
    name="Plan",
    type="select",
    options=["Free", "Pro", "Enterprise"],
)
print(column["key"])  # "plan"
```

**`PATCH /v1/api/data/columns/:column`**

### Change a column

Changes a column, addressed by key or id. Only the fields you send change. `key`, `kind` and `type` never change. Removing a choice from `options` does not remove it from rows that already hold it.

**Scope:** `data:manage`

**Body** — any of `name`, `description`, `options`, `allowNewOptions`, `aiEnabled`, `fillRule`.

**Returns** `{ column }`.

cURL:

```bash
curl -X PATCH https://api.ody.co/v1/api/data/columns/plan \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Tier", "options": ["Free", "Pro", "Enterprise", "Partner"] }'
```
TypeScript:

```ts
await ody.data.updateColumn("plan", { name: "Tier" });
```
Python:

```python
client.data.update_column("plan", name="Tier")
```

**`DELETE /v1/api/data/columns/:column`**

### Delete a column

Deletes the column, every value in it, and the history behind those values. This cannot be undone.

Deleting a column that Ody added (`auto: true`) also tells Ody not to add a column with that meaning again.

**Scope:** `data:manage`

**Returns** `{ ok: true }`.

cURL:

```bash
curl -X DELETE https://api.ody.co/v1/api/data/columns/plan \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
await ody.data.deleteColumn("plan");
```
Python:

```python
client.data.delete_column("plan")
```

**`GET /v1/api/data/columns/:column/summary`**

### Summarise a column

Counts one column across all contacts: how many contacts have a value, how many of those Ody filled, the most common values, and the range of a number or date column.

This is how you count a `multi_select` column by choice, which SQL cannot group.

**Scope:** `contacts:read`

**Returns** `{ summary }`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/columns/plan/summary \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
const summary = await ody.data.summarizeColumn("plan");
```
Python:

```python
summary = client.data.summarize_column("plan")
```

Response:

```json
{
  "summary": {
    "column": "plan",
    "name": "Plan",
    "contacts": 1840,
    "filled": 1212,
    "filledByAi": 430,
    "top": [
      { "value": "Pro", "count": 701 },
      { "value": "Free", "count": 455 },
      { "value": "Enterprise", "count": 56 }
    ],
    "numbers": null,
    "dates": null,
    "occurrences": null
  }
}
```

**`GET /v1/api/data/rows`**

### List rows

Returns one page of rows, one per contact, newest contact first unless you sort. Use `q`, `filter` and `sort` to narrow and order the page. For totals and grouping, use [SQL](#query-with-sql).

**Scope:** `contacts:read`

**Query parameters**

- `q` *string* — Search name, company, phone and e-mail.
- `filter` *string* — A JSON list of up to 20 filters. All of them must match. See below.
- `sort` *string* — A column key, or `contact.name`, `contact.company`, `contact.created_at`. With AI Contact on, also a [card field](#contact-card-fields) such as `contact.address_state` (every card field except `contact.ai_notes`).
- `dir` *string* — `asc` (default) or `desc`.
- `limit` *integer* — 1–100, default 50.
- `cursor` *string* — `nextCursor` from the previous page.

A filter is `{ "column", "op", "value" }`. `column` is a column key, or one of `contact.name`, `contact.phone`, `contact.email`, `contact.company`, `contact.tags`, `contact.created_at`. With AI Contact on, it can also be a [card field](#contact-card-fields), written `contact.address_state` or `contact.addressState`. `op` is one of `is`, `is_not`, `contains`, `not_contains`, `gt`, `gte`, `lt`, `lte`, `empty`, `not_empty`. `empty` and `not_empty` take no `value`.

**Returns** `{ rows: Row[], total: number, nextCursor: string | null }`. `total` counts every matching contact, not only this page. Rows in a list have no `cells`.

cURL:

```bash
curl -G https://api.ody.co/v1/api/data/rows \
  -H "Authorization: Bearer $ODY_API_KEY" \
  --data-urlencode 'filter=[{"column":"plan","op":"is","value":"Pro"},{"column":"seats","op":"gte","value":10}]' \
  --data-urlencode 'sort=renewal_date'
```
TypeScript:

```ts
const { rows, total, nextCursor } = await ody.data.rows({
  filter: [
    { column: "plan", op: "is", value: "Pro" },
    { column: "seats", op: "gte", value: 10 },
  ],
  sort: "renewal_date",
});

// Or every matching row, page after page:
for await (const row of ody.data.rowsAll({ q: "brightline" })) {
  console.log(row.contactId, row.data.plan);
}
```
Python:

```python
page = client.data.rows(
    filter=[
        {"column": "plan", "op": "is", "value": "Pro"},
        {"column": "seats", "op": "gte", "value": 10},
    ],
    sort="renewal_date",
)

# Or every matching row, page after page:
for row in client.data.rows_all(q="brightline"):
    print(row["contactId"], row["data"]["plan"])
```

**`GET /v1/api/data/rows/lookup`**

### Find a row by phone number or e-mail

Returns the row of the contact who has this phone number or e-mail address. Send exactly one of the two. This is the call to make when a conversation starts and your agent needs to know who it is talking to.

Phone numbers are matched in E.164. A number written another way, such as `(512) 555-0199`, is converted first.

**Scope:** `contacts:read`

**Query parameters**

- `phone` *string* — E.164. URL-encode the `+` as `%2B`.
- `email` *string* — Matching ignores case.

**Returns** `{ row }`, or `404 not_found` when no contact has it.

cURL:

```bash
curl "https://api.ody.co/v1/api/data/rows/lookup?phone=%2B15125550199" \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
const row = await ody.data.lookup({ phone: "+15125550199" });
console.log(row.data.plan, row.cells.plan?.source);
```
Python:

```python
row = client.data.lookup(phone="+15125550199")
print(row["data"]["plan"])
```

**`GET /v1/api/data/rows/:contactId`**

### Get a row

Returns one contact's row, with `cells`.

**Scope:** `contacts:read`

**Returns** `{ row }`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/rows/8b1d6f3e-2c4a-4e1b-9f0d-7a5c3e2b1a90 \
  -H "Authorization: Bearer $ODY_API_KEY"
```
TypeScript:

```ts
const row = await ody.data.get(contactId);
```
Python:

```python
row = client.data.get(contact_id)
```

**`PUT /v1/api/data/rows/:contactId`**

### Set values on a row

Sets the columns you send on one contact's row and leaves the other columns alone. `null` clears a value.

The call is all or nothing: if one value does not fit its column, nothing is written and the error names the column.

**Scope:** `contacts:write`

**Body**

- `data` *object* **required** — Column key → value.

**Returns** `{ row }`.

cURL:

```bash
curl -X PUT https://api.ody.co/v1/api/data/rows/8b1d6f3e-2c4a-4e1b-9f0d-7a5c3e2b1a90 \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "data": { "plan": "Enterprise", "seats": 40, "renewal_date": null } }'
```
TypeScript:

```ts
const row = await ody.data.set(contactId, {
  plan: "Enterprise",
  seats: 40,
  renewal_date: null,
});
```
Python:

```python
row = client.data.set(contact_id, {"plan": "Enterprise", "seats": 40, "renewal_date": None})
```

**`POST /v1/api/data/rows/upsert`**

### Find or create a contact and set values

Finds the contact by id, phone number or e-mail and sets values on its row. When no contact has the phone number or e-mail, the contact is created first. Use it to load rows from a CRM, a spreadsheet, an order system or an enrichment tool without looking up contact ids.

- **Values are checked first.** If one value does not fit its column, the call fails and nothing is created or written.
- **An existing contact's own fields are not changed.** `contact` is used only when a contact is created. Use [`PATCH /contacts/:id`](https://dev.ody.co/api/contacts#update-a-contact) to change a name or company.
- **A number that already called or texted is matched.** Ody creates a contact for every new number, so the upsert finds it rather than adding a second one.

One call writes one row. To load many rows, send one call per row and stay under the [rate limit](https://dev.ody.co/api/rate-limits) of 600 requests a minute.

**Scope:** `contacts:write`

**Body**

- `match` *object* **required** — Exactly one of `contactId`, `phone`, `email`.
- `contact` *object* — For a new contact: `firstName`, `lastName`, `company`, `phone`, `email`, `tags`.
- `data` *object* — Column key → value.

**Returns** `201` with `{ row, created: true }` when the contact was created, `200` with `{ row, created: false }` when it existed. A `contactId` that does not exist returns `404`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/rows/upsert \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "match": { "phone": "+15125550199" },
    "contact": { "firstName": "Dana", "lastName": "Reyes", "company": "Brightline" },
    "data": { "plan": "Pro", "seats": 12, "renewal_date": "2027-03-01" }
  }'
```
TypeScript:

```ts
const { row, created } = await ody.data.upsert({
  match: { phone: "+15125550199" },
  contact: { firstName: "Dana", lastName: "Reyes", company: "Brightline" },
  data: { plan: "Pro", seats: 12, renewal_date: "2027-03-01" },
});
```
Python:

```python
result = client.data.upsert(
    phone="+15125550199",
    contact={"firstName": "Dana", "lastName": "Reyes", "company": "Brightline"},
    data={"plan": "Pro", "seats": 12, "renewal_date": "2027-03-01"},
)
row, created = result["row"], result["created"]
```

**`POST /v1/api/data/query`**

### Query with SQL

Runs one read-only `SELECT` over two tables: `contacts` (one row per contact, with your columns) and `observations` (one row per thing Ody heard a contact say). The full dialect, with examples, is on [Database: SQL reference](https://dev.ody.co/api/data-sql).

Your statement is not sent to the database as written. Ody parses it, checks every name against your columns, and builds its own query with every value bound as a parameter. That is why only the listed keywords and functions work, and why an unsupported query fails with a message that says what to change.

**Scope:** `contacts:read`

**Body**

- `sql` *string* **required** — One `SELECT` statement, up to 4,000 characters.

**Returns** `{ columns, rows, rowCount, truncated }`. `columns` gives the name and type of each output column, and each row is an object keyed by those names. A call returns at most 1,000 rows; `truncated: true` means more rows matched, and you can page with `LIMIT` and `OFFSET`. A query that runs longer than 5 seconds is stopped and returns `400`.

cURL:

```bash
curl https://api.ody.co/v1/api/data/query \
  -H "Authorization: Bearer $ODY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "sql": "SELECT plan, count(*) AS contacts FROM contacts WHERE asked_about_pricing GROUP BY plan ORDER BY contacts DESC" }'
```
TypeScript:

```ts
const { rows } = await ody.data.query<{ plan: string; contacts: number }>(
  "SELECT plan, count(*) AS contacts FROM contacts WHERE asked_about_pricing GROUP BY plan ORDER BY contacts DESC",
);
```
Python:

```python
result = client.data.query(
    "SELECT plan, count(*) AS contacts FROM contacts WHERE asked_about_pricing GROUP BY plan ORDER BY contacts DESC"
)
for row in result["rows"]:
    print(row["plan"], row["contacts"])
```

Response:

```json
{
  "columns": [
    { "name": "plan", "type": "text" },
    { "name": "contacts", "type": "number" }
  ],
  "rows": [
    { "plan": "Pro", "contacts": 212 },
    { "plan": "Free", "contacts": 87 }
  ],
  "rowCount": 2,
  "truncated": false
}
```

## Errors

Errors use the [standard envelope](https://dev.ody.co/api/errors). The ones specific to the Database:

| Status | `code` | When |
|---|---|---|
| `400` | `invalid_argument` | A value does not fit its column, `data` names a column that does not exist, a filter is malformed, or the SQL is not supported. The message names the column or the position in the query. |
| `403` | `permission_denied` | The key lacks `contacts:read`, `contacts:write` or `data:manage`. |
| `404` | `not_found` | The contact or the column does not exist. A column `404` lists the keys that do. |
| `409` | `failed_precondition` | The Database is not switched on for this workspace. |

## Not available yet

- **Webhooks.** There is no event when a cell changes. Poll with `GET /data/rows`, or query `observations` by `observed_at`.
- **Bulk writes.** One call writes one row.
- **The contact's words.** `observations` gives the value, date and channel of what Ody heard, not the quote. The quote is shown in the app.
