Discovering content from Web APIs
To discover content from Web APIs
The basic method to discover content from Web APIs is:
- Add the data source.
- Write a pattern that specifies:
- The data source by name.
- A query to access the required information.
- Upload and activate the pattern.
- Scan the endpoint.
Queries
The query can be any one of the discovery restful functions, for example:
- discovery-restfulGet
- discovery-restfulPost
- discovery-restfulPatch
- discovery-restfulPut
- discovery-restfulDelete
To access a REST API endpoint
This procedure shows how to retrieve information from a REST API by using a REST API with basic authentication data source. The principles for other host data sources are identical, though you need to make minor modifications, for example, modify paths on Windows hosts running an SSH server.
- To create a REST API data source, from the main menu, select Manage > Data Sources.
- Click Add and select REST API with basic authentication from the menu.
For details on how to add a data source, see Adding-data-sources.
The following are example parameters:- Name—the name of the data source. For example, "RESTAPI basic DS". This is how patterns refer to and use the data source.
- Endpoint—the address (IPv4 or IPv6) of the host, or a resolvable hostname.
- Description—a free text description that is displayed on the Data Sources page.
- Username—the user name with which to access the host.
- Password—the corresponding password.
You might also need to add any parameters specific to the data source type. In this example, you might choose to modify the timeout, or choose a nonstandard port.
- Write a pattern that uses the data source you created and a query:
Specify the data source:
ds_host := discovery.dataSource("RESTAPI basic DS");Specify the query:
\\ returns the result from the API endpoint
result := discovery.restfulGet(ds_host, "basic_auth", "/api/1/device/1000");
- Upload and activate the pattern.
- Scan the host.
To view the information discovered
You can see the data source accesses for each discovery run that uses data sources.
- From the Discovery Access section in the Host page, click the latest Discovery Access.
- From the top row of the Endpoint section, select the Discovery Run.
- Select n Data Source Accesses Related.
The Data Source Access List page is displayed. If there is only one, the Data Source Access page is displayed. - Select the Data Source Access you want to view.