API - Create Host "error": "Required database field is empty"
-
Hello, I am trying to do a create host api call to eventually automate imaging some hardware. I can get data from fog all day long but when it comes to posting data to create a host it gives me this error: “error”: “Required database field is empty” this is what my post looks like:
$CreateHostJson = @{ "name"= "$vmname" "description"= "$Description" "primac" = "$MacAddress" "imagename" = "$ImageName" } $createHostURL = $baseUri +"/host/create/" $createHostResult = Invoke-RestMethod -Uri $createHostURL -Method POST -Headers $headers -body $CreateHostJson -ContentType "application/json"
Any help would be appreciated
-
Change
primac
tomacs: [“$MacAddress”]
-
Thanks, Is there any reason the Image name wouldn’t get populated? This works minus the image name:
$HostJson = @{
“name”= $vmname
“description”= $Description
“macs” = @($MacAddress)
“imagename” = $ImageName
}
$CreateHostJson = ConvertTo-Json($HostJson)
$createHostURL = $baseUri +“/host/create”
$createHostResult = Invoke-RestMethod -Uri $createHostURL -Method POST -body $CreateHostJson -Headers $headers -ContentType “application/json” -
Got it, this is the syntax from Powershell
$HostJson = @{
“name”= $vmname
“description”= $Description
“macs” = @($MacAddress)
“imageID”= $Image.id
“imagename” = $ImageName
}
$CreateHostJson = ConvertTo-Json($HostJson)
$createHostURL = $baseUri +“/host/create”
$createHostResult = Invoke-RestMethod -Uri $createHostURL -Method POST -body $CreateHostJson -Headers $headers -ContentType “application/json”