How to get all machines in Citrix Virtual Apps and Desktops
Use REST APIs to get all machines in your Citrix Virtual Apps and Desktops site.
Follow the prerequisites and examples to get started with this API.
You can make API requests using the PowerShell code, C# code, Python, or any tool that supports invoking the REST API.
Prerequisites to get all machines
- Read Get started with Citrix Cloud APIs section to ensure that you have the
bearer token
. - Get
siteid
from How to get site id API. - Invoke the API described in this document from a client host or from the API exploration tab to get all machines in the site.
Get all machines in your site using any REST API tool
Learn from the following example to get all machines in your Citrix Virtual Apps and Desktops site using any REST API tool.
Request
GET https://[DdcServerAddress]/cvad/manage/Machines HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
Authorization: CWSAuth bearer=<token-from-prerequisites>
Citrix-CustomerId: loy6oujtu6a4
Citrix-InstanceId: 22ded57c-0306-47e4-b6e8-fed6252759e1
<!--NeedCopy-->
Response
HTTP/1.1 200 OK
citrix-transactionid: f10859e0-63a9-4c2a-a51e-a126416246dc
content-Length: 1440
content-Type: application/json; charset=utf-8
date: "Mon, 07 Dec 2020 09:01:09 GMT"
Server: Citrix Systems, Inc.
{
"Items": [
{
"Id": "cf8582de-61dd-4c61-9649-636004c89907",
"Uid": 1,
"AgentVersion": null,
"AllocationType": "Random",
"ApplicationsInUse": [],
"AssociatedUsers": [],
"MachineCatalog": {
"Id": "b2a2acbc-bfe2-48cd-af62-c1c349789abb",
"Uid": 1,
"Name": "MC_01"
},
"ContainerScopes": [
{
"Scopes": [
{
...
}
],
"ScopeType": "MachineCatalog"
},
{
"Scopes": [
{
...
}
],
"ScopeType": "DeliveryGroup"
}
],
"ControllerDnsName": null,
"DeliveryGroup": {
"Id": "2544a873-39cb-4953-bb83-09afd3c6c0d7",
"Uid": 1,
"Name": "DG_01"
},
"DeliveryType": "DesktopsAndApps",
"Description": null,
"DesktopConditions": [],
"DnsName": "OrchVM-000001.DEVPORTAL.LOCAL",
"Hosting": {
...
},
...
"Name": "DEVPORTAL\\OrchVM-000001",
...
},
{
"Id": "8bd7c72f-1a4c-4e00-ae4f-bf2eb34457f9",
"Uid": 2,
"AgentVersion": null,
"AllocationType": "Random",
"ApplicationsInUse": [],
"AssociatedUsers": [],
"MachineCatalog": {
"Id": "b2a2acbc-bfe2-48cd-af62-c1c349789abb",
"Uid": 1,
"Name": "MC_01"
},
"ContainerScopes": [
{
"Scopes": [
{
...
}
],
"ScopeType": "MachineCatalog"
},
{
"Scopes": [
{
...
}
],
"ScopeType": "DeliveryGroup"
}
],
"ControllerDnsName": null,
"DeliveryGroup": {
"Id": "7b951c6b-b56a-473e-be8e-7745a1a83d8b",
"Uid": 2,
"Name": "DG_HR"
},
"DeliveryType": "DesktopsAndApps",
"Description": null,
"DesktopConditions": [],
"DnsName": "OrchVM-000002.DEVPORTAL.LOCAL",
"Hosting": {
"HostedMachineId": null,
"HostedMachineName": null,
"HostingServerName": null,
"LastHostingUpdateTime": "",
"HypervisorConnection": {
"Id": "",
"Uid": null,
"Name": null
},
"ImageOutOfDate": false
},
...
"Name": "DEVPORTAL\\OrchVM-000002",
...
}
]
}
<!--NeedCopy-->
Get all machines in your site using PowerShell
Learn from the following example to get all machines in your Citrix Virtual Apps and Desktops site using any PowerShell code.
function GetMachinesInSite {
param (
[Parameter(Mandatory=$true)]
[string] $customerid,
[Parameter(Mandatory=$true)]
[string] $siteid,
[Parameter(Mandatory=$true)]
[string] $bearerToken
)
$requestUri = "https://[DdcServerAddress]/cvad/manage/Machines"
$headers = @{
"Accept" = "application/json";
"Authorization" = "CWSAuth Bearer=$bearerToken";
"Citrix-CustomerId" = $customerid;
"Citrix-InstanceId" = $siteid;
}
$response = Invoke-RestMethod -Uri $requestUri -Method GET -Headers $headers
return $response
}
$customerid = "n2ypkklgy6cv"
$siteid = "12f7438-bf8e-42ba-b1b3-2eb75d098f57"
$bearerToken = "eyJ..."
$response = GetMachinesInSite $customerid $siteid $bearerToken
<!--NeedCopy-->
Get all machines in your site using C# code
Learn from the following example to get all machines in your Citrix Virtual Apps and Desktops site using any C# code.
public static async Task<string> GetMachinesInSite(
string customerid,
string siteid,
string bearerToken)
{
var requestUri = "https://[DdcServerAddress]/cvad/manage/Machines";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
client.DefaultRequestHeaders.Add("Citrix-CustomerId", customerid);
client.DefaultRequestHeaders.Add("Citrix-InstanceId", siteid);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("CWSAuth Bearer=" + bearerToken);
var response = await client.GetAsync(requestUri);
if (response != null)
{
var content = await response.Content.ReadAsStringAsync();
return content;
}
return null;
}
}
<!--NeedCopy-->
Get all machines in your site using Python
Learn from the following example to get all machines in your Citrix Virtual Apps and Desktops site using Python.
import requests
def get_machines_in_site(bearerToken, customerid, siteid):
request_uri = "https://[DdcServerAddress]/cvad/manage/Machines"
headers = {
'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
'Citrix-CustomerId': customerid,
'Citrix-InstanceId': siteid,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.get(request_uri, headers = headers)
return response.json()
<!--NeedCopy-->