ntrippcig
Contributor
Contributor

Horizon REST Call: /inventory/v1/desktop-pools/{id}/action/add-machines

Making a call and I have the pool ID correct and post the body in JSON:

[
  {
    "name""XXXXXXXXX",
    "user_id""S-XXXXXXXXXXXX"
  }
]
 
get this response:
{
    "status""BAD_REQUEST",
    "timestamp"1635764411101,
    "error_message""Desktop pool should be specified naming type"
}
 
Documentation says to send exactly what I am sending. What gives? what is this "Desktop pool should be specified naming type"
0 Kudos
17 Replies
chrisdhalstead
VMware Employee
VMware Employee

You should be only passing an array of machine ids to add to the pool.  You appear to be posting user details?

https://developer.vmware.com/apis/1169#/Inventory/addMachines 

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
ntrippcig
Contributor
Contributor

How about add-machines-by-name:

/inventory/v1/desktop-pools/{id}/action/add-machines-by-name

That's actually what I was trying first.  I don't see any other calls that can do the user assignment.  

0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

Are you looking to entitle manual pools or automated pools?

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

it's a manual persistent pool.  Users have been connecting to these desktops remotely over vpn/rdp and want to keep the desktop but start using Horizon.  They are entitled to the pool by group but I want to add the machine and assign a user to a specific machine because that's where their profiles and apps are. 

0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

Got it - let me see if there is a REST API for that.  It may only be available with PowerCLI

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
Tags (1)
0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

This endpoint should do it:

​/inventory​/v1​/machines​/{id}​/action​/assign-users

 

 

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

I just tried the add-machines call and that is complaining that the machine is not found in the VC:

 

  {
        "id""XXX",
        "status_code"404,
        "error_messages": [
            "Could not find machine on VC"
        ],
        "timestamp"1635870204537
    }
]
 
I've tried by VM name and by the VM ID in vcenter. Is there some other designation I should be using? When I click add in vcenter they are there. 
0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

It should be this endpoint:  

​/inventory​/v1​/machines​/{id}​/action​/assign-users

You need to get the machine ID from:  ​/inventory​/v1​/machines

 

 

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

That does return list of machines, but only ones that are already registered in pools.

0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

Are you trying to add physical machines with the Horizon Agent to a manual pool and then assign users to it?    What type of machine are you trying to add to the manual pool?

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

VMWare VMs in vcenter the connection servers are connected to

0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

ok make sure the VMs have a Horizon Agent installed.

Where do you see these machines in the Horizon console today? 

Are they under Inventory | Machines 

or 

Settings | Registered Machines

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

Agent is installed. The machines don't show in Inventory or Registered machines. I can Add from GUI so I am looking for the REST call to replicate that GUI function. 

0 Kudos
chrisdhalstead
VMware Employee
VMware Employee

what GUI are you talking about?  The Horizon console?

Are you talking about adding vCenter machines into a manual pool this way?

Screen Shot 2021-11-04 at 4.52.48 PM.png

Chris Halstead
Senior Staff Architect, EUC Technical Marketing
chalstead@vmware.com
Twitter: @chrisdhalstead
0 Kudos
ntrippcig
Contributor
Contributor

Says I do not have perms to upload images. Desktops -> manual pool -> add

0 Kudos
ntrippcig
Contributor
Contributor

I have the registration working but assigning users is failing

 

$desktop = Invoke-RestMethod "$($connectionservers)/rest/external/v1/virtual-machines?vcenter_id=$($vcenter_id)" -Method 'GET' -Headers $headers 
$desktop = $desktop | where-object {$_.name -eq $computer}
$pools = Invoke-RestMethod "$($connectionservers)/rest/inventory/v1/desktop-pools" -Method 'GET' -Headers $headers 
$pool_id = ($pools | Where-Object {$_.name -like $pool}).id
$desktopJ = "[
    $($desktop.id | ConvertTo-Json)
    ]"
$machineRegister = Invoke-RestMethod "$($connectionservers)/rest/inventory/v1/desktop-pools/$($pool_id)/action/add-machines" -Method "POST" -Headers $headers -Body ($desktopJ)
Invoke-RestMethod "$($connectionservers)/rest/inventory/v1/machines/$($machineRegister.id)/action/assign-users" -Method "POST" -Body "[`"XXXXXXXXXXXXXXXXXXXXX`"]"
Invoke-RestMethod: 
VMware Horizon
        function toggleError()
        {
            var errorElement = document.getElementById('errorDetails');
            if (errorElement && errorElement.style.display == 'none')
            {
                errorElement.style.display="block";
            }
            else
            {
                errorElement.style.display="none";
            }
        }
        function escapeHTML (str)
        {
            var div = document.createElement('div');
            var text = document.createTextNode(str);
            div.appendChild(text);
            return div.innerHTML;
        }







Error: Unsupported Media Type
The page you requested is not available.
        var url = escapeHTML(location.href);
        if (url.indexOf("http:") == 0 && 415 == "404") {
                document.write(" Try HTTPS instead.");
        }
Show Details
    Error code: 415
0 Kudos
pillayar
Contributor
Contributor

Did you get this to work? I am in a similar situation - need to add VMs to manual desktop and couldn't figure out where to get the machineID, as the VMs are not registered yet to any pools.

0 Kudos