Citrix DaaS REST APIs

How to start or stop recording of a session in Citrix DaaS

Use REST APIs to start or stop recording of a session 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 start or stop recording of a session

Start or stop recording of a session using any REST API tool

Learn from the following example to get recording status of a session using any REST API tool.

Session Recording enables IT personnel to monitor and examine user activity. It also supports internal controls for regulatory compliance and security monitoring. Similarly, Session Recording also aids in technical support by speeding problem identification and time-to-resolution.

Request to start recording a session

POST https://api.cloud.com/cvad/manage/Sessions/{id}/$startRecording 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-->

Request to stop recording a session

POST https://api.cloud.com/cvad/manage/Sessions/{id}/$stopRecording 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 to start or stop recording a session

HTTP/1.1 200 OK
citrix-transactionid: 44399a9e-18ea-4c16-b549-811fa252c7b6
content-length: 1746
content-Type: application/json; charset=utf-8
date: Tue,15 Mar 2022 08:07:17 GMT

{
    "Id": "313b84bb-2b66-4393-ad7b-3e08dccb4fd0",
    "Uid": 9,
    "ApplicationsInUse": [],
    "AppState": "Desktop",
    "AppStateLastChangeTime": "3/15/2022 7:41:46 AM",
    "FormattedAppStateLastChangeTime": "2022-03-15T07:41:46Z",
    "Brokering": {
        "AutonomouslyBrokered": false,
        "DurationMilliseconds": 249,
        "Time": "3/15/2022 7:41:15 AM",
        "FormattedTime": "2022-03-15T07:41:15Z",
        "UserName": "XF4B5\\Administrator",
        "UserSid": "S-1-5-21-3498310158-745772606-2686472752-500"
    },
    "Client": {
        "DeviceId": "WR_pp-gSk41sXlCJjiAJ",
        "HardwareId": "2C771263",
        "IPAddress": "10.12.14.48",
        "Name": "testpc",
        "Platform": "Windows",
        "ProductId": 1,
        "ReceiverIPAddress": "103.14.252.249",
        "ReceiverName": "WR_pp-gSk41sXlCJjiAJ",
        "Version": "22.2.0.4525"
    },
    "Connection": {
        "ConnectedViaHostName": null,
        "ConnectedViaIP": "10.108.96.166",
        "ConnectionMode": "Brokered",
        "LaunchedViaHostName": "",
        "LaunchedViaIP": null,
        "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": 30607,
    "EstablishmentTime": "3/15/2022 7:41:46 AM",
    "FormattedEstablishmentTime": "2022-03-15T07:41:46Z",
    "IsAnonymousUser": false,
    "IsHidden": false,
    "LogoffInProgress": false,
    "LogonInProgress": false,
    "Machine": {
        "Uid": 1,
        "AgentVersion": "2109.0.0.31047",
        "AllocationType": "Random",
        "ApplicationsInUse": null,
        "AssignedUsers": null,
        "AssociatedUsers": null,
        "AzureAdJoinedMode": "Unknown",
        "ContainerScopes": null,
        "ControllerDnsName": null,
        "DeliveryGroup": {
            "Id": "ca0d41c4-700b-49b1-aad9-42db9dcbee59",
            "Uid": 1,
            "Name": "WinOS"
        },
        "DeliveryType": null,
        "Description": null,
        "DesktopConditions": null,
        "DnsName": "W2K22-VDA.lab01",
        "Hosting": {
            "HostedMachineId": null,
            "HostedMachineName": null,
            "HostingServerName": null,
            "LastHostingUpdateTime": null,
            "FormattedLastHostingUpdateTime": null,
            "HypervisorConnection": {
                "Id": "00000000-0000-0000-0000-000000000000",
                "Uid": null,
                "Name": null
            },
            "ImageOutOfDate": false
        },
        "InMaintenanceMode": false,
        "DrainingUntilShutdown": false,
        "IPAddress": "10.108.56.131",
        "IsAssigned": null,
        "MachineType": "Physical",
        "LastConnectionFailure": null,
        "LastConnectionTime": null,
        "FormattedLastConnectionTime": null,
        "LastConnectionUser": null,
        "LastDeregistrationReason": null,
        "LastDeregistrationTime": null,
        "FormattedLastDeregistrationTime": null,
        "LastErrorReason": null,
        "LastErrorTime": null,
        "FormattedLastErrorTime": null,
        "LoadIndex": null,
        "MachineUnavailableReason": "Unknown",
        "OSType": "Windows 2022",
        "OSVersion": null,
        "PersistUserChanges": "OnLocal",
        "PowerActionPending": null,
        "PowerState": "Unknown",
        "ProvisioningType": "Manual",
        "PublishedApplications": null,
        "PublishedName": 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,
        "FormattedSessionStartTime": null,
        "SessionState": null,
        "SessionStateChangeTime": null,
        "FormattedSessionStateChangeTime": null,
        "SessionSupport": "MultiSession",
        "SessionUserName": null,
        "Sid": null,
        "SummaryState": "InUse",
        "WillShutdownAfterUse": null,
        "WindowsConnectionSetting": null,
        "Zone": {
            "Id": "41d64c14-03ac-4aba-9e0a-436d50e50fea",
            "Uid": null,
            "Name": "My Resource Location"
        },
        "SupportedPowerActions": null,
        "FaultState": "Unknown",
        "ContainerMetadata": null,
        "Tags": null,
        "UpgradeType": null,
        "UpgradeState": null,
        "UpgradeDetail": null,
        "Id": null,
        "MachineCatalog": {
            "Id": "818f479e-ac7b-46eb-a08c-435b26407ee3",
            "Uid": 1,
            "Name": "W2K22"
        },
        "Name": "XF4B5\\W2K22-VDA"
    },
    "SessionType": "Desktop",
    "StartTime": "3/15/2022 7:41:45 AM",
    "FormattedStartTime": "2022-03-15T07:41:45Z",
    "State": "Active",
    "StateChangeTime": "3/15/2022 7:41:46 AM",
    "FormattedStateChangeTime": "2022-03-15T07:41:46Z",
    "UntrustedUserName": "lab01\\administrator",
    "User": {
        "DisplayName": "",
        "SamName": null,
        "SamAccountName": null,
        "CommonName": null,
        "PrincipalName": "",
        "Oid": null,
        "Sid": "S-1-5-21-3498310158-745772606-2686472752-500",
        "GroupSids": null,
        "DenyOnlySids": null,
        "PasswordCanExpire": null,
        "DaysUntilPasswordExpiry": null,
        "IsBuiltIn": null,
        "IsGroup": null,
        "Name": "XF4B5\\Administrator",
        "StreetAddress": null,
        "City": null,
        "State": null,
        "Country": null,
        "Mail": null,
        "TelephoneNumber": null,
        "HomePhone": null,
        "Mobile": null,
        "Enabled": null,
        "Locked": null,
        "PropertiesFetched": 0,
        "Claims": null,
        "Directory": null,
        "Domain": null,
        "Forest": null,
        "Guid": null,
        "DistinguishedName": null,
        "CanonicalName": null,
        "PossibleLookupFailure": false,
        "DirectoryServer": null
    }
}
<!--NeedCopy-->

Start or stop recording of a session using PowerShell

Learn from the following example to start or stop recording of a session using any PowerShell code.

function StartSessionRecording {
    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://api.cloud.com/cvad/manage/Sessions/{0}/`$startRecording", $sessionid)
    $headers = @{
        "Accept" = "application/json";
        "Authorization" = "CWSAuth Bearer=$bearerToken";
        "Citrix-CustomerId" = $customerid;
        "Citrix-InstanceId" = $siteid;
   }

    $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -ContentType "application/json"
    return $response
}
$customerId = "customer1"
$siteId = "61603f15-cdf9-4c7f-99ff-91636601a795"
$sessionId = "56f1cbf3-1cc6-40cd-9c82-c95633ba88bb"
$bearerToken = "ey1.."
$response = StartSessionRecording $customerid $siteid $sessionId $bearerToken 

function StopSessionRecording {
    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://api.cloud.com/cvad/manage/Sessions/{0}/`$stopRecording", $sessionid)
    $headers = @{
        "Accept" = "application/json";
        "Authorization" = "CWSAuth Bearer=$bearerToken";
        "Citrix-CustomerId" = $customerid;
        "Citrix-InstanceId" = $siteid;
    }

    $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -ContentType "application/json"
    return $response
}

$customerId = "customer1"
$siteId = "61603f15-cdf9-4c7f-99ff-91636601a795"
$sessionId = "56f1cbf3-1cc6-40cd-9c82-c95633ba88bb"
$bearerToken = "ey1.." 
$response = StopSessionRecording $customerid $siteid $sessionId $bearerToken 
<!--NeedCopy-->

Start or stop recording of a session using C# code

Learn from the following example to start or stop recording of a session using any C# code.

public static async Task<string> StartSessionRecording(
    string customerid,
    string siteid,
    string bearerToken,
    string sessionid)
{
    var requestUri = $"https://api.cloud.com/cvad/manage/Sessions/{sessionid}/$startRecording";
    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("User-Agent", "c# App");
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("CwsAuth", "bearer=" + bearerToken);

        var response = await client.PostAsync(requestUri, null);

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

        return null;
    }
}
var task = StartSessionRecording(customerId, siteid, bearerToken, sessionid);
var result = task.Result;
string jsonFormat = JValue.Parse(result).ToString(Formatting.Indented);

public static async Task<string> StopSessionRecording(
    string customerid,
    string siteid,
    string bearerToken,
    string sessionid)
{
    var requestUri = $"https://api.cloud.com/cvad/manage/Sessions/{sessionid}/$stopRecording";
    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("User-Agent", "c# App");
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("CwsAuth", "bearer=" + bearerToken);

        var response = await client.PostAsync(requestUri, null);

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

        return null;
    }
}
var task = StopSessionRecording(customerId, siteid, bearerToken, sessionid);
var result = task.Result;
string jsonFormat = JValue.Parse(result).ToString(Formatting.Indented);
<!--NeedCopy-->

Start or stop recording of a session using Python

Learn from the following example to start or stop recording of a session using any Python code.

import requests 

def StartSessionRecording(bearerToken, customerid, sessionid, siteid):
    request_uri = "https://api.cloud.com/cvad/manage/Sessions/{0}/$startRecording".format(sessionid)
    headers = {
                'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
                'Citrix-CustomerId': customerid,
                'Citrix-InstanceId': siteid,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
              }

    response = requests.post(request_uri, headers = headers)

    return response.json()

def StopSessionRecording(bearerToken, customerid, sessionid, siteid):
    request_uri = "https://api.cloud.com/cvad/manage/Sessions/{0}/$stopRecording".format(sessionid)
    headers = {
                'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
                'Citrix-CustomerId': customerid,
                'Citrix-InstanceId': siteid,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
              }

    response = requests.post(request_uri, headers = headers)

    return response.json()
<!--NeedCopy-->
Resources
Citrix DaaS REST APIs OpenAPI Specification
Copy Download
How to start or stop recording of a session in Citrix DaaS