Hi,
Can someone help me on how to use search filter in Foreman API's.
Let's say, i want to get the reports for a specific host.
As per Foreman API guide, only following are possible.
ResourceDescription
GET /api/reports
<API documentation> List all
reports
GET /api/reports/:id
<API documentation> Show a report
POST /api/reports
<API documentation> Create a
report
DELETE /api/reports/:id
<API documentation> Delete a
report
GET /api/hosts/:host_id/reports/last
<API documentation> Show the last
report for a host
There is no direct API to get all the reports for a specific host. To get
this, i'm trying to use search filter like
https://puppetmaster/api/reports?search="host_name=Myhostname" with no
results.
Also, please tell me, how to use sort by in Foreman API's.
Thanks a lot.
Harish
Hi Harish,
> There is no direct API to get all the reports for a specific host. To get this, i'm trying to use search filter like https://puppetmaster/api/reports?search="host_name=Myhostname" with no results.
The key for filtering by host is 'host', not 'host_name'. You will want to ensure that you URL encode your query as well.
> Also, please tell me, how to use sort by in Foreman API's.
The parameter you want is "order" (http://www.katello.org/docs/3.1/api/apidoc/reports/index.html). You can see what options are available by logging into your Foreman instance, opening a host and clicking on "Reports". Once in there hover over the column headers to see the different options. For example, to order by "Last report" you would say:
?order=reported+ASC&search=host+%3D+my.host.name
(note the search parameter is URL encoded)
Regards,
j