Citrix Virtual Apps and Desktops REST APIs

How to get details of a machine on which a session is running

Use REST APIs to get detail of the machine on which a session is running 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 details of a machine on which a session is running

Get details of a machine on which a session is running using any REST API tool

Learn from the following example to get detail of the machine on which a specified session is running using any REST API tool.

Request

GET https://[DdcServerAddress]/cvad/manage/Sessions/{id}/Machine 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: 2edd8219-94e7-4157-8831-ce70f1360c95
content-Length: 4534
content-Type: application/json; charset=utf-8
date: "Wed, 09 Dec 2020 09:39:51 GMT"
Server: Citrix Systems, Inc.

{
    "AssignedClientName": null,
    "AssignedIPAddress": null,
    "AssignedUsers": [],
    "BrowserName": null,
    "ColorDepth": null,
    "FunctionalLevel": null,
    "IconId": "",
    "IsReserved": false,
    "LoadIndexes": [],
    "PublishedName": null,
    "SecureIcaRequired": null,
    "SessionsEstablished": 1,
    "SessionsPending": 0,
    "StoreFrontServersForHostedReceiver": [],
    "VMToolsState": "NotStarted",
    "Id": "f6239587-4fb1-43f4-8ae5-8a53cc995e7e",
    "Uid": 15,
    "AgentVersion": "1912.0.1000.24525",
    "AllocationType": "Random",
    "ApplicationsInUse": null,
    "AssociatedUsers": [
        {
            "DisplayName": "IdpUser-123456",
            "SamName": "HTLABS03\\IdpUser-123456",
            "SamAccountName": null,
            "CommonName": null,
            "PrincipalName": "IdpUser-123456@htlabs03.example.com",
            "Sid": "S-1-5-21-886277602-2428626936-2556752729-2162",
            "GroupSids": null,
            "DenyOnlySids": null,
            "PasswordCanExpire": null,
            "DaysUntilPasswordExpiry": null,
            "IsBuiltIn": null,
            "IsGroup": null,
            "Name": null,
            "StreetAddress": null,
            "City": null,
            "State": null,
            "Country": null,
            "Mail": null,
            "TelephoneNumber": null,
            "HomePhone": null,
            "Mobile": null,
            "Enabled": null,
            "Locked": null,
            "PropertiesFetched": 0,
            "Domain": null,
            "Forest": null,
            "Guid": null,
            "DistinguishedName": null,
            "CanonicalName": null,
            "PossibleLookupFailure": false,
            "DirectoryServer": null
        }
    ],
    "MachineCatalog": {
        "Id": "0520987c-0312-4e1c-bd09-7714fc8732ec",
        "Uid": 2,
        "Name": "Sales-B2"
    },
    "ContainerScopes": null,
    "ControllerDnsName": null,
    "DeliveryGroup": {
        "Id": "5c796610-cb80-40ae-8378-5cbd5cefbd89",
        "Uid": 2,
        "Name": "Integration"
    },
    "DeliveryType": "DesktopsAndApps",
    "Description": null,
    "DesktopConditions": [],
    "DnsName": "Sales-B2.htlabs03.example.com",
    "Hosting": {
        "HostedMachineId": "example-xd-5df7bda0-4d32-4248-8f0c-3b42fc3feee2-m6iw5/Sales-B2",
        "HostedMachineName": null,
        "HostingServerName": null,
        "LastHostingUpdateTime": "12/9/2020 6:08:57 AM",
        "HypervisorConnection": {
            "Id": "404c52a7-4a92-43cb-8d7f-18d781b829e5",
            "Uid": 1,
            "Name": "Sales-Vda"
        },
        "ImageOutOfDate": false
    },
    "InMaintenanceMode": false,
    "IPAddress": "10.107.128.28",
    "IsAssigned": false,
    "MachineType": "Virtual",
    "LastConnectionFailure": null,
    "LastConnectionTime": null,
    "LastConnectionUser": null,
    "LastDeregistrationReason": null,
    "LastDeregistrationTime": null,
    "LastErrorReason": null,
    "LastErrorTime": null,
    "LoadIndex": null,
    "Name": "HTLABS03\\Sales-B2",
    "OSType": "Windows 2019",
    "OSVersion": "Microsoft Windows NT 6.3.9600.0",
    "PersistUserChanges": "Discard",
    "PowerActionPending": false,
    "PowerState": "On",
    "ProvisioningType": "MCS",
    "PublishedApplications": [
        "WorkingApp_01"
    ],
    "RegistrationState": "Registered",
    "ScheduledReboot": "None",
    "SessionClientAddress": null,
    "SessionClientName": null,
    "SessionClientVersion": null,
    "SessionConnectedViaHostName": null,
    "SessionConnectedViaIP": null,
    "SessionCount": 1,
    "SessionLaunchedViaHostName": null,
    "SessionLaunchedViaIP": null,
    "SessionProtocol": null,
    "SessionSecureIcaActive": null,
    "SessionSmartAccessTags": null,
    "SessionStartTime": null,
    "SessionState": null,
    "SessionStateChangeTime": null,
    "SessionSupport": "SingleSession",
    "SessionUserName": null,
    "Sid": "S-1-5-21-886277602-2428626936-2556752729-2207",
    "SummaryState": "Disconnected",
    "WillShutdownAfterUse": true,
    "WindowsConnectionSetting": "LogonEnabled",
    "Zone": {
        "Id": "1d405094-3abe-4ab9-b304-b21522bcd3e6",
        "Uid": null,
        "Name": "htlabs03-EastUs"
    },
    "SupportedPowerActions": [
        "Reset",
        "Restart",
        "Shutdown",
        "PowerOff",
        "PowerOn"
    ],
    "FaultState": "None"
}
<!--NeedCopy-->

Get details of a machine on which a session is running using PowerShell

Learn from the following example to get detail of the machine on which a specified session is running using any PowerShell code.

function GetSessionMachine {
    param (
        [Parameter(Mandatory=$true)]
        [string] $customerid,
        [Parameter(Mandatory=$true)]
        [string] $siteid,
        [Parameter(Mandatory=$true)]
        [string] $sessionid,
        [Parameter(Mandatory=$true)]
        [string] $bearerToken
    )
    $requestUri = [string]::Format("https://[DdcServerAddress]/cvad/manage/Sessions/{0}/Machine", $sessionid)
    $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"
$sessionid = "56f1cbf3-1cc6-40cd-9c82-c95633ba88bb"
$bearerToken = "eyJ..."
$response = GetSessionMachine $customerid $siteid $sessionid $bearerToken 
<!--NeedCopy-->

Get details of a machine on which a session is running using C# code

Learn from the following example to get detail of the machine on which a specified session is running using any C# code.

public static async Task<string> GetSessionMachine(
    string customerid,
    string siteid,
    string sessionid,
    string bearerToken)
{
    var requestUri = string.Format("https://[DdcServerAddress]/cvad/manage/Sessions/{0}/Machine", sessionid);
    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 details of a machine on which a session is running using Python

Learn from the following example to get detail of the machine on which a specified session is running using Python.

import requests 

def GetSessionMachine(bearerToken, customerid, siteid, sessionid):
    request_uri = "https://[DdcServerAddress]/cvad/manage/Sessions/{0}/Machine".format(sessionid)
    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-->
Resources
Citrix Virtual Apps and Desktops REST APIs OpenAPI Specification
Copy Download
How to get details of a machine on which a session is running