2.2. 了解 JSON 响应格式
调用 API 返回的结果,采用 JSON 格式。API 调用返回单选响应或响应集合的结果。
注意
					以下示例请求使用 python3 来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python 而不是 python3。
				
单一对象的 JSON 响应格式
					您可以使用单一对象 JSON 响应来操作单个对象。对单个对象的 API 请求需要对象的唯一标识符 :id。
				
这是 Satellite 域的单对象请求格式的示例,ID 为 23:
请求示例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/domains/23 | python3 -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/domains/23 | python3 -m json.tool响应示例:
集合的 JSON 响应格式
集合是主机和域等对象列表。集合 JSON 响应的格式由 metadata 字段和 results 部分组成。
以下是 Satellite 域列表的集合请求格式的示例:
请求示例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/domains | python3 -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/domains | python3 -m json.tool响应示例:
响应元数据字段
API 响应使用以下元数据字段:
- 
						total- 没有搜索参数的对象总数。
- 
						subtotal- 返回给定搜索参数的对象数量。如果没有搜索,则 subtotal 等于 total。
- 
						页面- 页面号。
- 
						per_page- 每个页面返回的最大对象数量。
- 
						limit- 在集合响应中返回指定的对象数量。
- 
						offset- 返回集合前跳过的对象数量。
- 
						search- 基于scoped_scoped语法的搜索字符串。
- sort- 
								by- 通过什么字段指定 API 对集合进行排序。
- 
								order- 排序顺序,即 ASC 升序,或 DESC 表示降序。
 
- 
								
- 
						结果- 对象的集合。