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



  • 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”



  • 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”


  • Senior Developer

    Change primac to macs: [“$MacAddress”]


Log in to reply
 

376
Online

39.4k
Users

11.1k
Topics

105.3k
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.