Trying foreman v2 api to add puppetclass to host

Hi Karin,

Here is what you need to do to create a new puppetclass association for a host

  • change PUT to POST
  • pass the puppetclass_id as data -d { }, rather than the id in the URL

This line should work for you

curl -X POST -d "{"puppetclass_id":2}" -H 'Accept:version=2' -H "Content-Type:application/json" -H "Accept:application/json"

To DELETE a puppetclass, then you can pass the puppetclass id in the URL

curl -X DELETE -H 'Accept:version=2' -H "Content-Type:application/json" -H "Accept:application/json"

The same is true for adding/removing puppetclass from hostgroups

We had some discussions about this, and thought this approach was the most RESTful.

Since you are on the latest foreman develop version, you can go to /apidoc and then click the v2 link to see the preliminary API v2 documentation (subject to changes :slight_smile:


··· ----- Original Message ----- From: "Karim Boumedhel" To: "Joseph Magen" Sent: Friday, April 5, 2013 6:09:00 PM Subject: trying foreman v2 api to add puppetclass to host

Hi Joseph,
sorry to bother you, i m trying to use this feature you implemented
using current git version of foreman, as it s someone we re planning to
use at my client
actually i m using python with pycurl to proceed but even the following
curl call doesnt seem to work:

/curl -X PUT -H ‘Accept: version=2’ -H “Content-Type:application/json”
-H "Accept:application/json"
where 10 is the id of my host
and 2 is the id of my class

as per PUT /api/hosts/:id/puppetclasses/:id

I keep getting {“message”:“Not found”} …any hints?
thank you for the great work, btw!

Karim Boumedhel
Red Hat Senior Consultant

Cell: +34 676389555