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

# 分页

> 基于游标，因为支持队列在您阅读时仍在变化。

列表端点返回一页数据和游标：

```json theme={null}
{
  "data": [ ... ],
  "next_cursor": "eyJpZCI6..."
}
```

将 `next_cursor` 作为 `cursor` 查询参数传回，即可获取下一页。当 `next_cursor` 为 `null` 时，表示已到达末尾。

```bash theme={null}
# First page
curl "https://api.minidesk.ai/v1/tickets?limit=50" \
  -H "Authorization: Bearer $MINIDESK_TOKEN"

# The next one
curl "https://api.minidesk.ai/v1/tickets?limit=50&cursor=eyJpZCI6..." \
  -H "Authorization: Bearer $MINIDESK_TOKEN"
```

`limit` 的取值范围为 1 到 100，默认值为 25。

## 为什么不使用页码

支持队列在您阅读时仍在变化。使用偏移量时，如果在两次请求之间有工单到达，所有行都会向下移动，导致第 2 页重复第 1 页的某一行。如果有工单被解决，行会向上移动，导致某一行被完全跳过。

游标指向结果中的某个位置，而不是从开头计数的偏移量，因此上述两种情况都不会发生。

## 遍历每一页

```js theme={null}
async function everyTicket(token, query = {}) {
  const tickets = [];
  let cursor;

  do {
    const params = new URLSearchParams({ ...query, limit: "100" });
    if (cursor) params.set("cursor", cursor);

    const response = await fetch(
      `https://api.minidesk.ai/v1/tickets?${params}`,
      { headers: { Authorization: `Bearer ${token}` } },
    );

    if (!response.ok) throw new Error(`${response.status}`);

    const page = await response.json();
    tickets.push(...page.data);
    cursor = page.next_cursor;
  } while (cursor);

  return tickets;
}
```

> [!NOTE]
>
> `data` 数组为空但 `next_cursor` 不为 null 的情况是可能的。应在 `next_cursor` 为 `null` 时停止，而不是在返回空页时停止。

## 筛选

筛选条件放在查询字符串中，并以 AND 组合。它们是游标的一部分，因此在整个遍历过程中应保持一致。在遍历中途更改筛选条件会使游标失去意义。

| 参数 | 说明 |
| - | - |
| `status` | 一个状态，或用逗号分隔的多个状态：`open` 或 `new,open` |
| `priority` | `low`、`normal`、`high`、`urgent` |
| `category` | 精确匹配。已弃用：由分诊添加的第一个标签 |
| `assignee_id` | 成员 ID |
| `q` | 对请求者详细信息和消息正文进行全文搜索 |

逗号形式之所以存在，是因为队列对“进行中”的定义是同时看到 `new` 和 `open`，为此发明第六个状态将意味着筛选词汇与状态机不匹配。

```bash theme={null}
curl "https://api.minidesk.ai/v1/tickets?status=new,open&priority=urgent" \
  -H "Authorization: Bearer $MINIDESK_TOKEN"
```


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