6.5. 使用搜索分页控制
您可以使用 per_page
和 page
分页参数来限制 API 搜索查询返回的搜索结果。per_
参数指定每个页面的结果数,page 参数指定根据 page
per_page
参数计算的页面,以返回。
当您没有指定任何分页参数时,要返回的默认项目数量被设置为 1000,但 per_page
值的默认值是 20,当您指定 page
参数时应用它。
本例返回 ID 为 1
的机构的激活码列表。列表中包含每个页面 30 个键,并返回第二个页面。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
6.5.1. 返回多个页面
您可以使用 for
循环结构来获取多个结果页面。本示例将第 1 页的内容视图的 3 页返回,每个页为 5 个结果。
bash 脚本
for i in seq 1 3; do \ curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \ done
$ for i in seq 1 3; do \
curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \
done