Bug #4805
closedAPI search method not working for opratingsystem type of objects.
Description
Trying to retrieve opearating system properties via API an empty set of results is returned when using "?search" method in the url.
Attached the result of calling the following urls:
https://<foreman_server>/api/v2/operatingsystems
https://<foreman_server>/api/v2/operatingsystems?search=CentOS
Files
Updated by Dominic Cleal over 10 years ago
Try using a "attribute = value" style of searching instead of relying on free text search. The same search rules as in the UI (which has a useful auto-complete) apply here, so "name = CentOS" will return all CentOS operating systems.
Updated by Xavier Naveira over 10 years ago
- File operatingsystemsbyname.htm operatingsystemsbyname.htm added
- File operatingsystemsbyfullname.htm operatingsystemsbyfullname.htm added
Hi Dominic,
Thank you for your answer.
Unfortunately using "attribute=value" doesn't seem to work either.
When searching using the following urls I get the whole list of operating systems in my Foreman installation (see results attached)
https://&lt;foreman_server&gt;/api/v2/operatingsystems?name=CentOS
https://&lt;foreman_server&gt;/api/v2/operatingsystems?fullname=CentOS 6.3
Another way to search for objects that I'm using successfully when looking for hosts is to use their name in the url like this:
https://&lt;foreman_server&gt;/api/v2/hosts/&lt;name_of_the_server>
So I thought to give it a try and do the same and test:
https://&lt;foreman_server&gt;/api/v2/operatingsystems/CentOS 6.3
But it seems to be a problem with the parsing because the call aboive throws back:
{
"error": {
"message": "Resource operatingsystem not found by id 'CentOS 6'"
}
}
Updated by Dominic Cleal over 10 years ago
The "attribute=value" is still passed within the "search" parameter, sorry that wasn't clear. For example:
https://foreman_server/api/v2/operatingsystems?search=fullname=CentOS 6.3
Have a look at the GUI for a better idea, you'll be able to search for something and reuse the same search string against the API.
The parse issue has been fixed in #4201 for Foreman 1.5.0.
Updated by Xavier Naveira over 10 years ago
Ok, so searching like this:
https://foreman_server/api/v2/operatingsystems?search=fullname=CentOS 6.3
Gives back:
{
"error": {
"message": "Field 'fullname' not recognized for searching!",
"class": "ScopedSearch::QueryNotSupported"
}
}
But I see your point and the parsing issue solved is all that I need.
Thank you for your help! You may now close this issue.
Updated by Dominic Cleal over 10 years ago
- Status changed from New to Resolved
Oh sorry, I copied your example without reading and checking it. It looks like we don't have a field at the moment for the "fullname", since that area (the concatenated name) is a bit complex and messy. It may be better to search for a specific name, major and minor. Anyway, glad that helped a bit, closing.