Unable to create hosts with the foreman API

Anybody have any idea why I'm getting the following message:

Unprocessable entity Host::Managed (id: new):
Name can't be blank
Environment can't be blank

When I try and create hosts via the API. I've verified that I've included
the information correctly. The json is also valid.

Here's what I'm doing with curl. I have included both name and environment:

curl -XPOST -s -d'{"host": {"operatingsystem_id": 1, "mac":
"00:25:B5:10:00:6E", "environment_id": "1", "architecture_id": 2, "name":
"dalindexstore01", "ip": "10.10.28.201", "domain_id": 2, "puppet_proxy_id":
9, "hostgroup_id": 1}}' -k -u user:pass "
https://myforemaninstall.com/api/hosts"

The result I get back is this:

{
"host": {
"errors": {
"environment_id": [
"can't be blank"
],
"name": [
"can't be blank"
]
},
"full_messages": [
"Name can't be blank",
"Environment can't be blank"
],
"id": null
}
}

On the foreman logs I see this:

tarted POST "/api/hosts" for 192.168.42.222 at Wed Oct 23 22:44:12 +0000
2013
Processing by Api::V1::HostsController#create as JSON
Parameters: {"{"host": {"operatingsystem_id": 1, "mac":
"00:25:B5:10:00:6E", "environment_id": "1", "architecture_id": 2,
"name": "dalindexstore01", "ip": "10.10.28.201", "domain_id": 2,
"puppet_proxy_id": 9, "hostgroup_id": 1}}"=>nil}

Unprocessable entity Host::Managed (id: new):
Name can't be blank
Environment can't be blank

Rendered api/v1/errors/unprocessable_entity.json.rabl (1.7ms)
Completed 422 Unprocessable Entity in 25ms (Views: 2.5ms | ActiveRecord:
3.3ms)

··· -- Stephen Wood www.heystephenwood.com

> Anybody have any idea why I'm getting the following message:
>
> Unprocessable entity Host::Managed (id: new):
> Name can't be blank
> Environment can't be blank
>
> When I try and create hosts via the API. I've verified that I've included
> the information correctly. The json is also valid.
>
> Here's what I'm doing with curl. I have included both name and environment:
>
> curl -XPOST -s -d'{"host": {"operatingsystem_id": 1, "mac":
> "00:25:B5:10:00:6E", "environment_id": "1", "architecture_id": 2, "name":
> "dalindexstore01", "ip": "10.10.28.201", "domain_id": 2, "puppet_proxy_id":
> 9, "hostgroup_id": 1}}' -k -u user:pass "
> https://myforemaninstall.com/api/hosts"
>

try adding:
-H "Content-type:application/json"

Ohad

··· On Thu, Oct 24, 2013 at 1:46 AM, Stephen Wood wrote:

The result I get back is this:

{
“host”: {
“errors”: {
“environment_id”: [
“can’t be blank”
],
“name”: [
“can’t be blank”
]
},
“full_messages”: [
“Name can’t be blank”,
“Environment can’t be blank”
],
“id”: null
}
}

On the foreman logs I see this:

tarted POST “/api/hosts” for 192.168.42.222 at Wed Oct 23 22:44:12 +0000
2013
Processing by Api::V1::HostsController#create as JSON
Parameters: {"{“host”: {“operatingsystem_id”: 1, “mac”:
“00:25:B5:10:00:6E”, “environment_id”: “1”, “architecture_id”: 2,
“name”: “dalindexstore01”, “ip”: “10.10.28.201”, “domain_id”: 2,
“puppet_proxy_id”: 9, “hostgroup_id”: 1}}"=>nil}

Unprocessable entity Host::Managed (id: new):
Name can’t be blank
Environment can’t be blank

Rendered api/v1/errors/unprocessable_entity.json.rabl (1.7ms)
Completed 422 Unprocessable Entity in 25ms (Views: 2.5ms | ActiveRecord:
3.3ms)

Stephen Wood
www.heystephenwood.com


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks for the tip, Ohad! That did the trick nicely.

··· On Wed, Oct 23, 2013 at 10:46 PM, Ohad Levy wrote:

On Thu, Oct 24, 2013 at 1:46 AM, Stephen Wood smwood4@gmail.com wrote:

Anybody have any idea why I’m getting the following message:

Unprocessable entity Host::Managed (id: new):
Name can’t be blank
Environment can’t be blank

When I try and create hosts via the API. I’ve verified that I’ve included
the information correctly. The json is also valid.

Here’s what I’m doing with curl. I have included both name and
environment:

curl -XPOST -s -d’{“host”: {“operatingsystem_id”: 1, “mac”:
“00:25:B5:10:00:6E”, “environment_id”: “1”, “architecture_id”: 2, “name”:
“dalindexstore01”, “ip”: “10.10.28.201”, “domain_id”: 2, “puppet_proxy_id”:
9, “hostgroup_id”: 1}}’ -k -u user:pass "
https://myforemaninstall.com/api/hosts"

try adding:
-H “Content-type:application/json”

Ohad

The result I get back is this:

{
“host”: {
“errors”: {
“environment_id”: [
“can’t be blank”
],
“name”: [
“can’t be blank”
]
},
“full_messages”: [
“Name can’t be blank”,
“Environment can’t be blank”
],
“id”: null
}
}

On the foreman logs I see this:

tarted POST “/api/hosts” for 192.168.42.222 at Wed Oct 23 22:44:12 +0000
2013
Processing by Api::V1::HostsController#create as JSON
Parameters: {"{“host”: {“operatingsystem_id”: 1, “mac”:
“00:25:B5:10:00:6E”, “environment_id”: “1”, “architecture_id”: 2,
“name”: “dalindexstore01”, “ip”: “10.10.28.201”, “domain_id”: 2,
“puppet_proxy_id”: 9, “hostgroup_id”: 1}}"=>nil}

Unprocessable entity Host::Managed (id: new):
Name can’t be blank
Environment can’t be blank

Rendered api/v1/errors/unprocessable_entity.json.rabl (1.7ms)
Completed 422 Unprocessable Entity in 25ms (Views: 2.5ms | ActiveRecord:
3.3ms)

Stephen Wood
www.heystephenwood.com


You received this message because you are subscribed to the Google Groups
“Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
“Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


Stephen Wood

> Thanks for the tip, Ohad! That did the trick nicely.
>

Great… next time consider using hammer instead :wink:

Ohad

··· On Thu, Oct 24, 2013 at 10:21 PM, Stephen Wood wrote:

On Wed, Oct 23, 2013 at 10:46 PM, Ohad Levy ohadlevy@gmail.com wrote:

On Thu, Oct 24, 2013 at 1:46 AM, Stephen Wood smwood4@gmail.com wrote:

Anybody have any idea why I’m getting the following message:

Unprocessable entity Host::Managed (id: new):
Name can’t be blank
Environment can’t be blank

When I try and create hosts via the API. I’ve verified that I’ve
included the information correctly. The json is also valid.

Here’s what I’m doing with curl. I have included both name and
environment:

curl -XPOST -s -d’{“host”: {“operatingsystem_id”: 1, “mac”:
“00:25:B5:10:00:6E”, “environment_id”: “1”, “architecture_id”: 2, “name”:
“dalindexstore01”, “ip”: “10.10.28.201”, “domain_id”: 2, “puppet_proxy_id”:
9, “hostgroup_id”: 1}}’ -k -u user:pass “
https://myforemaninstall.com/api/hosts

try adding:
-H “Content-type:application/json”

Ohad

The result I get back is this:

{
“host”: {
“errors”: {
“environment_id”: [
“can’t be blank”
],
“name”: [
“can’t be blank”
]
},
“full_messages”: [
“Name can’t be blank”,
“Environment can’t be blank”
],
“id”: null
}
}

On the foreman logs I see this:

tarted POST “/api/hosts” for 192.168.42.222 at Wed Oct 23 22:44:12 +0000
2013
Processing by Api::V1::HostsController#create as JSON
Parameters: {"{“host”: {“operatingsystem_id”: 1, “mac”:
“00:25:B5:10:00:6E”, “environment_id”: “1”, “architecture_id”: 2,
“name”: “dalindexstore01”, “ip”: “10.10.28.201”, “domain_id”: 2,
“puppet_proxy_id”: 9, “hostgroup_id”: 1}}"=>nil}

Unprocessable entity Host::Managed (id: new):
Name can’t be blank
Environment can’t be blank

Rendered api/v1/errors/unprocessable_entity.json.rabl (1.7ms)
Completed 422 Unprocessable Entity in 25ms (Views: 2.5ms | ActiveRecord:
3.3ms)

Stephen Wood
www.heystephenwood.com


You received this message because you are subscribed to the Google
Groups “Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.


Stephen Wood
www.heystephenwood.com


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.