Need help with Foreman API

Hello there :smiley:

I need some help with Foreman API.
I am new to the Foreman, no exp. at all (only created some VM’s ) :roll_eyes::roll_eyes:
My task is to create golang script which will output info (like: hostgroup, env., location, organization and classes) of specific host.
I must use Foreman API, but I don’t know how.
I created simple version of algorithm, how would it work ->
-> Input (username/password/domain)
-> Login (username/password)
-> Find host by his domain name in “Hosts”
-> Copy all info about host into list
-> Get from the list all what I need
-> Output (list)
Can you help me with this?
I will appreciate any help.
Thank you all :slight_smile:

Hi,
the algorithm you have outlined seems reasonable. What exactly it is that makes you struggle with API? Do you have problems with authentication, calling the endpoint or finding the endpoint with data you need?

To see the documentation for all endpoints, the best is to navigate to https://$(hostname)/apidoc.html on your Foreman.

For finding a host by name, I would use a search which you can specify in params. An example using curl:

I am afraid I will not be much of a help with Go, but the net/http seems like a place to start for creating a request. When you receive a response, it is just about parsing the JSON and doing whatever you need with received data.

Hope this helps,
O.

I am also new to Foreman however find “hammer” extremely useful for what you are trying to achive. Give that a try if that help in your case. :slight_smile: