Citrix DaaS REST APIs

How to perform an advanced search for machines in Citrix DaaS

Use REST APIs to perform an advanced search on machines in your Citrix DaaS (formerly Citrix Virtual Apps and Desktops service) 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 perform an advanced search for machines

  • Read the Get started with Citrix Cloud APIs section to ensure that you have the bearer token.
  • Get siteid from How to get site id API.
  • Get the search filters ready.
  • Invoke the API described in this document from a client host or from the API exploration tab to perform an advanced search on machines within the site.

Perform an advanced search for machines using any REST API tool

Learn from the following example to do an advanced search on machines of the Windows Server OS type and that contains orch in their names using any REST API tool.

For how to perform various searches and sort results, see the API specification.

Request

POST https://api.cloud.com/cvad/manage/Machines/$search 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

{
    "SearchFilters": [
        {
            "Property": "MachineName",
            "Value": "Orch",
            "Operator": "ContainsLike"
        },
        {
            "Property": "SessionSupport",
            "Value": "MultiSession",
            "Operator": "Equals"
        }
    ]
}
<!--NeedCopy-->

Response

HTTP/1.1 200 OK
citrix-transactionid: f2aac10b-35e8-401d-89a0-7f1898847ce6 
content-Length: 1461
content-Type: application/json; charset=utf-8
date: "Mon, 07 Dec 2020 10:34:52 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": [
                        {
                            "Id": "00000000-0000-0000-0000-000000000000",
                            "Uid": null,
                            "Name": "All",
                            "Description": null,
                            "IsBuiltIn": true,
                            "IsAllScope": true,
                            "IsTenantScope": false,
                            "TenantId": null,
                            "TenantName": null
                        }
                    ],
                    "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": {
                "HostedMachineId": null,
                "HostedMachineName": null,
                "HostingServerName": null,
                "LastHostingUpdateTime": "",
                "HypervisorConnection": {
                    "Id": "",
                    "Uid": null,
                    "Name": null
                },
                "ImageOutOfDate": false
            },
            ...
            "Name": "DEVPORTAL\\OrchVM-000001",
            ...
            "Zone": {
                "Id": "5b8d7588-48db-4ea7-a38b-a7bbc32199d8",
                "Uid": null,
                "Name": "My Resource Location"
            },
            "SupportedPowerActions": [],
            "FaultState": "None"
        },
        ...
    ],
    "TotalItems": 5
}
<!--NeedCopy-->

Perform an advanced search for machines using PowerShell

Learn from the following example to do an advanced search on machines of the Windows Server OS type and that contains orch in their names using any PowerShell code.

function SearchMachinesInSite {
    param (
        [Parameter(Mandatory=$true)]
        [string] $customerid,
        [Parameter(Mandatory=$true)]
        [string] $siteid,
        [Parameter(Mandatory=$true)]
        [string] $bearerToken,
        [Parameter(Mandatory=$true)]
        [string] $body
    )
    $requestUri = "https://api.cloud.com/cvad/manage/Machines/`$search"
    $headers = @{
        "Accept" = "application/json";
        "Authorization" = "CWSAuth Bearer=$bearerToken";
        "Citrix-CustomerId" = $customerid;
        "Citrix-InstanceId" = $siteid;
        "Content-Type" = "application/json";
    }
    
    $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body
    return $response
}

$customerId = "customer1"
$siteId = "61603f15-cdf9-4c7f-99ff-91636601a795"
$bearerToken = "ey1.."
$body = @"
{
    "SearchFilters": [
        {
            "Property": "MachineName",
            "Value": "Orch",
            "Operator": "ContainsLike"
        },
        {
            "Property": "SessionSupport",
            "Value": "MultiSession",
            "Operator": "Equals"
        }
    ]
}
"@
$response = SearchMachinesInSite $customerid $siteid $bearerToken $body 
<!--NeedCopy-->

Perform an advanced search for machines using C# code

Learn from the following example to do an advanced search on machines of the Windows Server OS type and that contains orch in their names using any C# code.

public static async Task<string> SearchMachinesInSite(
    string customerid,
    string siteid,
    string bearerToken,
    MachineAndSessionSearchRequestModel model)
{
    var requestUri = "https://api.cloud.com/cvad/manage/Machines/$search";
    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.Add("Content-Type", "application/json");
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("CWSAuth Bearer=" + bearerToken);

        var jsonBody = JsonConvert.SerializeObject(model, new JsonSerializerSettings
        {
            Converters = new JsonConverter[] { new StringEnumConverter() }
        });

        var response = await client.PostAsync(requestUri, new StringContent(jsonBody, Encoding.UTF8, "application/json"));

        if (response != null)
        {
            var content = await response.Content.ReadAsStringAsync();
            return content;
        }

        return null;
    }
}
<!--NeedCopy-->

Perform an advanced search for machines using Python

Learn from the following example to do an advanced search on machines of the Windows Server OS type and that contains orch in their names using Python.

import requests 

def search_machines_in_site(bearerToken, customerid, siteid):
    request_uri = "https://api.cloud.com/cvad/manage/Machines/$search"
    headers = {
                'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
                'Citrix-CustomerId': customerid,
                'Citrix-InstanceId': siteid,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
              }
    payload = json.dumps({
        "SearchFilters": [
            {
                "Property": "MachineName",
                "Value": "Orch",
                "Operator": "ContainsLike"
            },
            {
                "Property": "SessionSupport",
                "Value": "MultiSession",
                "Operator": "Equals"
            }
        ] 
    })

    response = requests.post(request_uri, headers = headers, verify = False, data = payload)

    return response.json()
<!--NeedCopy-->
Resources
Citrix DaaS REST APIs OpenAPI Specification
Copy Download
How to perform an advanced search for machines in Citrix DaaS