How to get all sessions in Citrix DaaS
Use REST APIs to get all exsiting sessions 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 get all sessions
- 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. - Invoke the API described in this document from a client host or from the API exploration tab to get all existing sessions in the site.
Get all existing sessions in your site using any REST API tool
Learn from the following example to get all existing sessions in your Citrix DaaS site using any REST API tool.
This API may return a large number of items, therefore, optional parameters limit
and continuationToken
can be set to get the results in smaller subsets by multiple calls.
Request
GET https://api.cloud.com/cvad/manage/Sessions?limit=100 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: ce0d3943-e294-4fc8-b2c6-85271d4a0c3b
content-Length: 8320
content-Type: application/json; charset=utf-8
date: "Tue, 08 Dec 2020 11:34:57 GMT"
Server: Citrix Systems, Inc.
{
"Items": [
{
"Id": "41ba32e9-d12b-485c-afd2-c4d0d047cd8b",
"Uid": 8,
"ApplicationsInUse": [
{
"Id": "00000000-0000-0000-0000-000000000000",
"Uid": null,
"Name": "WorkingApp_1"
}
],
"AppState": "Active",
"AppStateLastChangeTime": "11/16/2020 2:01:04 PM",
"Brokering": {
"AutonomouslyBrokered": false,
"DurationMilliseconds": null,
"Time": null,
"UserName": null,
"UserSid": null
},
"Client": {
"DeviceId": null,
"HardwareId": "55667788",
"IPAddress": "10.107.1.120",
"Name": "",
"Platform": "Unknown",
"ProductId": 9,
"ReceiverIPAddress": null,
"ReceiverName": null,
"Version": "v1.0"
},
"Connection": {
"ConnectedViaHostName": null,
"ConnectedViaIP": "10.107.1.34",
"ConnectionMode": "Brokered",
"LaunchedViaHostName": null,
"LaunchedViaIP": "20.62.252.155",
"Protocol": "Hdx",
"SecureIcaActive": false,
"SmartAccessTags": []
},
"ContainerScopes": [
{
"Scopes": [
{
"Id": "00000000-0000-0000-0000-000000000000",
"Uid": null,
"Name": "All",
"Description": null,
"IsBuiltIn": true,
"IsAllScope": true,
"IsTenantScope": false,
"TenantId": null,
"TenantName": null
}
],
"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"
}
],
"EstablishmentDurationMilliseconds": 22260,
"EstablishmentTime": "11/16/2020 2:01:04 PM",
"IsAnonymousUser": false,
"IsHidden": false,
"LogoffInProgress": false,
"LogonInProgress": false,
"Machine": {
"Id": null,
"Uid": 15,
"AgentVersion": "1912.0.1000.24525",
"AllocationType": "Random",
"ApplicationsInUse": null,
"AssociatedUsers": null,
"MachineCatalog": {
"Id": "0520987c-0312-4e1c-bd09-7714fc8732ec",
"Uid": 2,
"Name": "Sales-B"
},
"ContainerScopes": null,
"ControllerDnsName": null,
"DeliveryGroup": {
"Id": "5c796610-cb80-40ae-8378-5cbd5cefbd89",
"Uid": 2,
"Name": "Sales"
},
"DeliveryType": null,
"Description": null,
"DesktopConditions": null,
"DnsName": "Sales-B03.htlabs04.example.com",
"Hosting": {
"HostedMachineId": null,
"HostedMachineName": null,
"HostingServerName": null,
"LastHostingUpdateTime": null,
"HypervisorConnection": {
"Id": "00000000-0000-0000-0000-000000000000",
"Uid": null,
"Name": "SalesVda"
},
"ImageOutOfDate": false
},
"InMaintenanceMode": false,
"IPAddress": "10.107.128.208",
"IsAssigned": null,
"MachineType": "Virtual",
"LastConnectionFailure": null,
"LastConnectionTime": null,
"LastConnectionUser": null,
"LastDeregistrationReason": null,
"LastDeregistrationTime": null,
"LastErrorReason": null,
"LastErrorTime": null,
"LoadIndex": null,
"Name": "HTLABS04\\Sales-B03",
"OSType": "Windows 2019",
"OSVersion": null,
"PersistUserChanges": "Discard",
"PowerActionPending": null,
"PowerState": "Unknown",
"ProvisioningType": "MCS",
"PublishedApplications": null,
"RegistrationState": null,
"ScheduledReboot": "Unknown",
"SessionClientAddress": null,
"SessionClientName": null,
"SessionClientVersion": null,
"SessionConnectedViaHostName": null,
"SessionConnectedViaIP": null,
"SessionCount": null,
"SessionLaunchedViaHostName": null,
"SessionLaunchedViaIP": null,
"SessionProtocol": null,
"SessionSecureIcaActive": null,
"SessionSmartAccessTags": null,
"SessionStartTime": null,
"SessionState": null,
"SessionStateChangeTime": null,
"SessionSupport": "SingleSession",
"SessionUserName": null,
"Sid": null,
"SummaryState": "Disconnected",
"WillShutdownAfterUse": null,
"WindowsConnectionSetting": null,
"Zone": {
"Id": "1d405094-3abe-4ab9-b304-b21522bcd3e6",
"Uid": null,
"Name": "htlabs04-EastUs"
},
"SupportedPowerActions": null,
"FaultState": "Unknown"
},
"SessionType": "Application",
"StartTime": "11/16/2020 2:01:04 PM",
"State": "Disconnected",
"StateChangeTime": "11/16/2020 2:02:49 PM",
"UntrustedUserName": "HTLABS04\\DevUser1",
"User": {
"DisplayName": "DevUser1",
"SamName": null,
"SamAccountName": null,
"CommonName": null,
"PrincipalName": "DevUser1@htlabs04.example.com",
"Sid": "S-1-5-21-886277602-2428626936-2556752729-2162",
"GroupSids": null,
"DenyOnlySids": null,
"PasswordCanExpire": null,
"DaysUntilPasswordExpiry": null,
"IsBuiltIn": null,
"IsGroup": null,
"Name": "HTLABS04\\DevUser1",
"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
}
}
],
"ContinuationToken": null,
"TotalItems": 1
}
<!--NeedCopy-->
Get all existing sessions in your site using PowerShell
Learn from the following example to get all existing sessions in your Citrix DaaS site using any PowerShell code.
function GetSessionsInSite {
param (
[Parameter(Mandatory=$true)]
[string] $customerid,
[Parameter(Mandatory=$true)]
[string] $siteid,
[Parameter(Mandatory=$true)]
[string] $bearerToken
)
$requestUri = "https://api.cloud.com/cvad/manage/Sessions"
$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 = GetSessionsInSite $customerid $siteid $bearerToken
<!--NeedCopy-->
Get all existing sessions in your site using C# code
Learn from the following example to get all existing sessions in your Citrix DaaS site using any C# code.
public static async Task<string> GetSessionsInSite(
string customerid,
string siteid,
string bearerToken)
{
var requestUri = "https://api.cloud.com/cvad/manage/Sessions";
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 existing sessions in your site using Python
Learn from the following example to get all existing sessions in your Citrix DaaS site using Python.
import requests
def GetSessions(bearerToken, customerid, siteid):
request_uri = "https://api.cloud.com/cvad/manage/Sessions"
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-->