Poul Sørensen
2011-Nov-20 21:49 UTC
[Puppet Users] Foreman API, problem when creating hostgroups
I am trying to create a hostgroup using the Foreman API
(foreman-0.4-0.1rc1.noarch):
Using perl v.5.14.2, REST::Client et. al., ending up with sending:
POST /hostgroups
{"name":"api-created-
hostgroup","architecture_id":"","medium_id":"","environment_id":"","operatingsystem_id":"","ptable_id":"","puppetmaster":"puppet.dev.somewhere.com","root_pass":""}
which returns a 422-error
[that is: 422 Unprocessable Entity (WebDAV) (RFC 4918) - The request
was well-formed but was unable to be followed due to semantic errors.]
Processing HostgroupsController#create (for 10.20.7.81 at 2011-11-20
22:14:54) [POST]
Parameters: {"architecture_id"=>"",
"name"=>"api-created-hostgroup",
"puppetmaster"=>"puppet.dev.somewhere.com",
"action"=>"create",
"root_pass"=>"[FILTERED]",
"medium_id"=>"", "ptable_id"=>"",
"environment_id"=>"",
"controller"=>"hostgroups",
"operatingsystem_id"=>""}
Failed to save: Name can''t be blank or contain trailing white spaces.
Completed in 47ms (View: 2, DB: 12) | 422 Unprocessable Entity [http://
puppet.dev.somewhere.com/hostgroups]
I can easily do "GET /hostgroups" and all the other GET''s
documented
in the API, so I _think_ that my usage is correct...
but I guess something must be wrong somewhere:
> Failed to save: Name can''t be blank or contain trailing white
spaces.
I even tried with GET/POST (from LWP)
GET
http://apiusername:apiuserpassword@puppet.dev.somewhere.com/hostgroups?format=json
works fine
echo ''{"name":"api-created-
hostgroup","architecture_id":"","medium_id":"","environment_id":"","operatingsystem_id":"","ptable_id":"","puppetmaster":"puppet.dev.somewhere.com","root_pass":""}''
| POST
http://apiusername:apiuserpassword@puppet.dev.somewhere.com/hostgroups?format=json
{"errors":[["name","can''t be blank or contain
trailing white
spaces."]]}
Hope you can point out my error!
Poul
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Ohad Levy
2011-Nov-21 07:29 UTC
Re: [Puppet Users] Foreman API, problem when creating hostgroups
CC foreman users list. 2011/11/20 Poul Sørensen <poulhsorensen@gmail.com>:> I am trying to create a hostgroup using the Foreman API > (foreman-0.4-0.1rc1.noarch): > Using perl v.5.14.2, REST::Client et. al., ending up with sending: > > POST /hostgroups > {"name":"api-created- > hostgroup","architecture_id":"","medium_id":"","environment_id":"","operatingsystem_id":"","ptable_id":"","puppetmaster":"puppet.dev.somewhere.com","root_pass":""} > > which returns a 422-error > [that is: 422 Unprocessable Entity (WebDAV) (RFC 4918) - The request > was well-formed but was unable to be followed due to semantic errors.] > > > Processing HostgroupsController#create (for 10.20.7.81 at 2011-11-20 > 22:14:54) [POST] > Parameters: {"architecture_id"=>"", "name"=>"api-created-hostgroup", > "puppetmaster"=>"puppet.dev.somewhere.com", "action"=>"create", > "root_pass"=>"[FILTERED]", "medium_id"=>"", "ptable_id"=>"", > "environment_id"=>"", "controller"=>"hostgroups", > "operatingsystem_id"=>""} > Failed to save: Name can''t be blank or contain trailing white spaces. > Completed in 47ms (View: 2, DB: 12) | 422 Unprocessable Entity [http:// > puppet.dev.somewhere.com/hostgroups]it looks like you are missing the hostgroup parameter hash, afair, if you look at the look, all attributes are values of the key hostgroup. btw: make sure that you are using the right content-type (application/json) and pass along the user credentials (as basic auth) if they are required in your setup. Ohad btw: 0.4. has been released and has a lot of enchantments in the api area, might worth upgrading.> > I can easily do "GET /hostgroups" and all the other GET''s documented > in the API, so I _think_ that my usage is correct... > but I guess something must be wrong somewhere: > >> Failed to save: Name can''t be blank or contain trailing white spaces. > > I even tried with GET/POST (from LWP) > > GET http://apiusername:apiuserpassword@puppet.dev.somewhere.com/hostgroups?format=json > works fine > > echo ''{"name":"api-created- > hostgroup","architecture_id":"","medium_id":"","environment_id":"","operatingsystem_id":"","ptable_id":"","puppetmaster":"puppet.dev.somewhere.com","root_pass":""}'' > | POST http://apiusername:apiuserpassword@puppet.dev.somewhere.com/hostgroups?format=json > {"errors":[["name","can''t be blank or contain trailing white > spaces."]]} > > > Hope you can point out my error! > > Poul > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Poul Sørensen
2011-Nov-21 13:05 UTC
[Puppet Users] Re: Foreman API, problem when creating hostgroups
On Nov 21, 8:29 am, Ohad Levy <ohadl...@gmail.com> wrote:> CC foreman users list. > > 2011/11/20 Poul Sørensen <poulhsoren...@gmail.com>: > > > I am trying to create a hostgroup using the Foreman API > > > > POST /hostgroups > > {"name":"api-created-hostgroup",...","puppetmaster":"puppet.dev.somewhere.com",...} > > > which returns a 422-error > > Failed to save: Name can''t be blank or contain trailing white spaces. > > it looks like you are missing the hostgroup parameter hash, afair, if > you look at the look, all attributes are values of the key hostgroup.Wrapping the request-body as "{ hostgroup => $body }" surely solved the problem. For some reason, I''ve missed it in the doc, where it actually is very clear http://theforeman.org/projects/foreman/wiki/API> btw: 0.4. has been released and has a lot of enchantments in the api > area, might worth upgrading.System upgraded earlier today... Thanks for a swift response! regards Poul -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.