blob: 9a975accf75b8e782aa167e9b9ecbef56ab3a761 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
---
title: "Pagination"
description: "Handle large memory collections with pagination"
---
Handle large memory collections efficiently using pagination to process data in manageable chunks.
## Basic Pagination
<Tabs>
<Tab title="TypeScript">
```typescript
// Get first page
const page1 = await client.documents.list({
limit: 20,
page: 1
});
// Get next page
const page2 = await client.documents.list({
limit: 20,
page: 2
});
console.log(`Page 1: ${page1.memories.length} memories`);
console.log(`Page 2: ${page2.memories.length} memories`);
```
</Tab>
<Tab title="Python">
```python
# Get first page
page1 = client.documents.list(limit=20, page=1)
# Get next page
page2 = client.documents.list(limit=20, page=2)
print(f"Page 1: {len(page1.memories)} memories")
print(f"Page 2: {len(page2.memories)} memories")
```
</Tab>
<Tab title="cURL">
```bash
# Get first page
curl -X POST "https://api.supermemory.ai/v3/documents/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit": 20, "page": 1}'
# Get next page
curl -X POST "https://api.supermemory.ai/v3/documents/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"limit": 20, "page": 2}'
```
</Tab>
</Tabs>
## Loop Through Pages
<Tabs>
<Tab title="TypeScript">
```typescript
let currentPage = 1;
let hasMore = true;
while (hasMore) {
const response = await client.documents.list({
page: currentPage,
limit: 50
});
console.log(`Page ${currentPage}: ${response.memories.length} memories`);
hasMore = currentPage < response.pagination.totalPages;
currentPage++;
}
```
</Tab>
<Tab title="Python">
```python
current_page = 1
has_more = True
while has_more:
response = client.documents.list(page=current_page, limit=50)
print(f"Page {current_page}: {len(response.memories)} memories")
has_more = current_page < response.pagination.total_pages
current_page += 1
```
</Tab>
<Tab title="cURL">
```bash
# Manual pagination with bash loop
for page in {1..5}; do
echo "=== Page $page ==="
curl -X POST "https://api.supermemory.ai/v3/documents/list" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"page\": $page, \"limit\": 20}" | \
jq '.memories | length'
done
```
</Tab>
</Tabs>
<Info>
Use larger `limit` values (50-100) for pagination to reduce the number of API calls needed.
</Info>
|