首页 > 解决方案 > API 请求协助

问题描述

我不熟悉调用第三方 REST API。

我有一个需要 ID (/sites/{id}/) 的 API。因为我不知道我头顶上的 ID 并且想查询多个 ID,所以无论如何要通配此 ID 以使其运行通过并检查实例 ID 的 1 到 10?或者这更像是一个 python 集成?

标签: rest

解决方案


如上所述,如果一个 API 恰好有一个参数“id”,那么是否可以扫描所有可用的 ID(或 1 到 10 之间的任何 ID)完全取决于 API。

在您的情况下,API(用于 help.rapid7.com)有据可查。它似乎有一个“列出站点”的端点,它应该给你你正在寻找的东西:

https://help.rapid7.com/insightvm/en-us/api/index.html#operation/getSites

Sites
GET /api/3/sites
Server URL

https://help.rapid7.com/api/3/sites
Retrieves a paged resource of accessible sites.


PARAMETERS
Query Parameters
* page  integer <int32>
  Default: 0
  The index of the page (zero-based) to retrieve.

* size  integer <int32>
  Default: 10
  The number of records per page to retrieve.

* sort    
  Multiple query params of string
  The criteria to sort the records by, in the format: 
    property[,ASC|DESC]. 
  The default sort order is  ascending.
  Multiple sort criteria can be specified using multiple sort query parameters.

您可能想要执行以下操作:

  • 调用 /api/3/sites(带有过滤器)以获取您感兴趣的网站列表,然后
  • /sites/{id}/为您想要详细信息的列表中的每个站点进行连续调用。

推荐阅读