Add Host Records into Folder ​
POST /userapi/hostsinfolders
Adding a new Host record to be embedded beneath an existing Host Folder can be achieved by making a POST request on the URL, with appropriate fields forming the HTTP message body. This method does not add a host record, but simply shows the record nested beneath a Host Folder.
The user executing the API script must be given access to the following:
- On the screen Administration -> Feature Access -> Hosts tab : 'Specify which users are allowed to have access to the main Hosts Menu'
- The user must also have access to the Host Folder itself
Powershell
#Add Host record into Folder by Host ID
$Body = @{
HostID = "5466"
NestUnderFolderID = "350"
}
$jsonData = $Body | ConvertTo-Json
#Add Host record into Folder by Host Name
$Body = @{
HostName = "abcserver.halox.net"
NestUnderFolderID = "350"
}
$jsonData = $Body | ConvertTo-Json
$PasswordstateURL = 'https://passwordstate/userapi'
$result = Invoke-Restmethod -Method Post -Uri $PasswordstateURL'/hostsinfolders' -ContentType "application/json" -Body $jsonData -Header @{ "UserID" = "<UserID>" ; "APIKey" = "<APIKey>" }
Write-Output $resultJson
# Response
HTTP/1.1 200
[
{
"HostID":"5466",
"HostName":"abcserver.halox.net",
"HostType":"Windows",
"OperatingSystem":"Windows Server 2012",
"DatabaseServerType":"",
"SQLInstanceName":"",
"DatabasePortNumber":"",
"RemoteConnectionType":"RDP",
"RemoteConnectionPortNumber":"3389",
"RemoteConnectionParameters":"",
"Tag":"MyServer",
"Title":"",
"SiteID":"0",
"SiteLocation":"Internal",
"InternalIP":"192.168.1.57",
"ExternalIP":"",
"MACAddress":"28-C2-DD-E2-52-0E",
"SessionRecording":"False",
"VirtualMachine":"True",
"VirtualMachineType":"VMware",
"Notes":"",
"JobID":"",
"FolderID":"350"
}
]