There are occasions where there is no specific API endpoint that will give you exactly what you are looking for within the product, however, with the use of filtering it is possible to extract your desired information by filtering a response from another endpoint.
For example, we have an API call that gets a list of all implemented countermeasures of a product (/api/v1/products/{product-id}/controls/implemented) or one that gets a list of all required countermeasures of a product (/api/v1/products/{product-id}/controls/required) but there is no endpoint for getting a list of the recommended ones.
To achieve this, we have an API call that returns a list of all the countermeasures of a product (/api/v1/products/{product-id}/controls) and filtering the output of this API call, for example, adding the following jq command, can return us the desired list.
| jq '.[] | select(.state == "Recommended").ref'
The completed API call would be:
curl -s -X 'GET' \
'https://<instance>.iriusrisk.com/api/v1/products/<project_id>/controls' \
-H 'accept: application/json' \
-H 'api-token: <token>' \
| jq '.[] | select(.state == "Recommended").ref'
Note that the <instance> and the <token> variables need to be replaced for the real ones.
Comments
0 comments
Article is closed for comments.