# Query content and iterate documents

## List published content

```ts
const { data, meta } = await cms.content.list({
  limit: 20,
  offset: 0,
  status: "published",
  sort: "updated_at",
  dir: "desc",
});
```

`cms` is a client created with `createClient`. Content lists return `data` plus `meta`. Field projection, include options, and `where` filters use the server’s collection contract.

## Create and update a record

```ts
const { data: article } = await cms.content.create({
  collectionId: "articles",
  title: "Hello",
  status: "draft",
  data: { body: "First draft" },
});
await cms.content.update(article.id, { title: "Updated draft" });
```

Use a collection id that exists in your CMS. Fields must satisfy its schema. Test writes on disposable records and retain ids for later updates.

## Iterate the documents API

```ts
for await (const document of cms.documents.iterate({
  type: "articles",
  locale: "en",
  limit: 20,
})) {
  console.log(document.id);
}
```

Documents use keyset pagination with `{updatedAt, id}` cursors, rather than the content API’s offsets. Do not mix the pagination contracts. The iterator advances document pages until the server reports no next cursor.