Can't create host in foreman 1.16.2 using json POST request

Hello, I am using foreman 1.16.2 and I am trying to create new host using API v2. I used example from 1.21 so is there chance this is some old bug I am experiencing or change of api? I send POST request via curl, I can create new domain but host fail.

createhost.json

{
  "host": {
    "name": "testhost11",
    "environment_id": 334344675,
    "domain_id": 22495316,
    "ptable_id": 1007981705,
    "medium_id": 980190962,
    "architecture_id": 501905019,
    "operatingsystem_id": 1073012828,
    "puppet_proxy_id": 182953976,
    "compute_resource_id": 980190962,
    "root_pass": "xybxa6JUkz63w",
    "location_id": 255093256,
    "organization_id": 447626438,
    "ip": "10.0.0.20",
    "mac": "52:53:00:1e:85:93",
    "compute_attributes": {
      "cpus": 4,
      "memory": 1024
    }
  }
}

This is my script

#! /bin/sh
#   
curl -k -u Name:Pass -H "Accept: version=2,application/json" -H "Content-Type: application/json" \
        -X POST -d "@createhost.json" https://myserver.com/api/hosts

This is my error

{
  "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."}
}

And this is error on server side.

Processing by Api::V2::HostsController#create as JSON
2019-06-04 14:05:36 46c25a42 [app] [I]   Parameters: {"host"=>{"name"=>"testhost11", "environment_id"=>334344675, "domain_id"=>22495316, "ptable_id"=>1007981705, "medium_id"=>980190962, "architecture_id"=>501
905019, "operatingsystem_id"=>1073012828, "puppet_proxy_id"=>182953976, "compute_resource_id"=>980190962, "root_pass"=>"[FILTERED]", "location_id"=>255093256, "organization_id"=>447626438, "ip"=>"10.0.0.2
0", "mac"=>"52:53:00:1e:85:93", "compute_attributes"=>{"cpus"=>4, "memory"=>1024}}, "apiv"=>"v2"}
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: foreman_admin (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Expire fragment views/tabs_and_title_records-9 (0.2ms)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: foreman_admin (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: Me (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Authorized user Me(Its Me)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: Me (administrator)
2019-06-04 14:05:37 46c25a42 [app] [W] Action failed
 | NoMethodError: undefined method `provided_attributes' for nil:NilClass

5 versions is quite a gap, it would be hard to pinpoint any specific change done during that time frame (over a year of development). I would recommend trying to use the example and field definitions from the 1.16 manual or apidoc (also available on your server at e.g. https://foreman.example.com/apidoc/).

A quick google search points to a possible culprit at Bug #24348: hammer host create returns ISE when LibVirt compute-resource is not in correct organization - Foreman - but no idea if this is actually the issue you are hitting or not, and as 1.16 is long out of support any bugs found in it will not be investigated or fixed as they may have already been fixed in newer versions.

@topkek123 I don’t have any specific pointers but sometimes it helps if you check in the logs what arguments is the UI sending for hosts that succeed. Sometimes even empty hash of e.g. volume attributes makes the difference. Using what UI sends and removing the unnecessary bits one by one helped me a few times.