> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notcms.com/llms.txt
> Use this file to discover all available pages before exploring further.

# List Items

> Query and list multiple items from your Notion databases

## Basic Usage

Fetch all items from a database:

```typescript theme={null}
import { nc } from "./notcms/schema";

const [posts, error] = await nc.query.blog.list();

if (!error) {
  posts.forEach(post => {
    console.log(post.title);
  });
}
```

## Type Safety

NotCMS provides full type inference for list results:

```typescript theme={null}
// Infer array type
type BlogPosts = typeof nc.query.blog.$inferPages;

// Use in your functions
function processPosts(posts: BlogPosts) {
  posts.forEach(post => {
    // Full type safety and IDE autocomplete
    console.log(post.title);
    console.log(post.properties.published);
  });
}
```

## Filter and sort

```typescript theme={null}
const [posts, error] = await nc.query.blog.list({
  where: {
    published: true,
    language: "ja",
    released_at: { on_or_before: new Date() },
  },
  sort: { released_at: "desc" },
});
```

Property names and operands are inferred from your schema. Conditions are combined with AND and compare the published values, including locked properties. `list()` without arguments still returns all pages.

| Operator | Property types |
| - | - |
| Direct value, `equals`, `not_equals` | checkbox, number, strings, formula (string or number) |
| `is_empty: true`, `is_not_empty: true` | All types |
| `contains` | multi\_select (exact element match) |
| `before`, `after`, `on_or_before`, `on_or_after` | date, created\_time, last\_edited\_time; accepts an ISO string or `Date` |

At most 10 conditions can be combined, including multiple operators on a property. Empty means a missing property, `null`, an empty string or an empty array. `not_equals` also matches empty values; use `is_empty` to match `null` explicitly.

Dates are compared in UTC. A date without a time is midnight UTC (09:00 in Japan), and a timestamp without a timezone is also UTC. A date range uses its start. Invalid dates are rejected.

`sort` accepts exactly one scalar property with `"asc"` or `"desc"`. Array properties cannot be sorted. Empty values come last in either direction. Ties, and lists without `sort`, use registration order followed by page ID. Unknown properties, unsupported operators and invalid inputs return HTTP 400 through the usual error tuple.

## Retrieve related pages by ID

A relation contains Notion page IDs. Retrieve the related pages from a database you select, with at most 100 IDs per call:

```typescript theme={null}
const [posts, postsError] = await nc.query.blog.list({ where: { published: true } });
if (postsError) throw postsError;
const ids = [...new Set(posts.flatMap(post => post.properties.writers ?? []))];
const [writers, writersError] = await nc.query.writers.list({ where: { id: { in: ids } } });
if (writersError) throw writersError;
const writerById = new Map(writers.map(writer => [writer.id, writer]));
const orderedWriters = ids.flatMap(id => {
  const writer = writerById.get(id);
  return writer ? [writer] : [];
});
```

If there are more than 100 unique IDs, split them into batches of 100. An empty list returns no pages; more than 100 IDs returns HTTP 400. Unknown, deleted, unsynced, and out-of-scope pages are omitted. IDs are deduplicated and UUID hyphens/case are normalized. Responses use the normal sort order, not the input order; use a Map to restore the relation order as above (canonical IDs returned by Notion and NotCMS match).

The returned properties are typed for the selected database. No recursive expansion occurs, so self-references or cycles do not issue extra requests. `id: { in: [...] }` targets page IDs. A schema property named `id` still supports its regular conditions such as `id: { equals: "custom-value" }`.

For error tuples, HTTP 429, and retry guidance, see [Errors and Rate Limits](https://docs.notcms.com/en/usage/errors-and-rate-limits.md).

## Next Steps

> [card] [Get Single Item](https://docs.notcms.com/en/usage/get.md)
>
> Learn to fetch individual items

> [card] [Initializing Client](https://docs.notcms.com/en/usage/initializing-client.md)
>
> Set up your schema and server-side credentials


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.