# PagePromise

> What every list() returns: await it for one page ({ data, has_more, next_cursor }), or iterate it with for await to walk every item of every page.

Source: https://docs.tryyoursize.com/reference/node/page-promise/

*Class* · `@tryyoursize/node`

What every `list()` returns: await it for one page (`{ data, has_more, next_cursor }`), or iterate it with `for await` to walk every item of every page.

## Methods

- **`then / catch / finally`** (`Promise<TPage>`, required): Awaiting gives the first page.
- **`[Symbol.asyncIterator]()`** (`AsyncGenerator<TItem>`, required): `for await (const item of list)`: every item, following `next_cursor`.
- **`pages()`** (`AsyncGenerator<TPage>`, required): Every page, starting with the first.
- **`autoPagingToArray(opts?)`** (`Promise<TItem[]>`, required): Collects items across pages, at most `opts.limit` (default 10,000).
- **`autoPagingEach(fn)`** (`Promise<void>`, required): Calls `fn` for each item; return `false` to stop.

## Example

**Node.js**

```ts
const first = await tys.products.list({ limit: 20 });
const all = await tys.products.list().autoPagingToArray({ limit: 500 });
await tys.fitGroups.list().autoPagingEach((g) => { console.log(g.name); });
```

**Python**

```python
page = tys.products.list(limit=20)
next_page = page.next_page()
for product in page.auto_paging_iter():
    ...
```

## See also

- [Pagination](https://docs.tryyoursize.com/guides/pagination.md)
