API - Cannot update host

I am using phpCurl to access the API. I tried to update an existing host and while I receive a HTTP 200 response the host info does not get updated.

$url = "http://myserver.domain/api/hosts/$hostid";
$data = array("name" => $hostname, "host" => array("name" => $hostname, "mac"=> $hostmac));
$json = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "myuser:mypass"); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json; charset=utf-8',
      'Content-Length: ' . strlen($json),
      'Cache-Control: no-cache',
      'X-Requested-With: XMLHttpRequest',
      'X-HTTP-Method-Override: PUT',
$result = curl_exec($ch);

Can you post the production log from the katello server for that request?

I suspect the XMLHttpRequest is interpreted as a something other than a resource modification for the hist.

1 Like

I also forgot to thank you for posting this and letting us know about potential issues. So thank you!

1 Like

What I found is that if I change it to a POST and use the method override header it works with some versions of php. Still looking into it.