Citrix DaaS REST APIs

How to set new priority for polices in a policy set in Citrix DaaS

Use REST APIs to set new priority for polices in a policy set within 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 set new priority for polices in a policy set

Set new priority for polices in a policy set from your site using any REST API tool

Learn from the following example to set new priority for polices in a policy set in your Citrix DaaS site using any REST API tool.

Request

PATCH https://api.cloud.com/cvad/manage/gpo/policyPriorities?policySetGuid={policySetGuid} 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

[
  "de496042...",
  "c7131c3b..."
]
<!--NeedCopy-->

Response

HTTP/1.1 200 OK
citrix-transactionid: 7cefafc8...
content-Length: 4
content-Type: application/json; charset=utf-8
date: "Wed,08 Nov 2023 05:31:34 GMT"

{
    true
}
<!--NeedCopy-->

Set new priority for polices in a policy set from your site using PowerShell

Learn from the following example to set new priority for polices in a policy set within your Citrix DaaS site using PowerShell.


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

$customerId = "customer1"
$siteId = "61603f15-cdf9-4c7f-99ff-91636601a795"
$bearerToken = "ey1.."
$policySetName = "PS02"

$policySets = GetPolicySets $customerid $siteid $bearerToken 
$policySet = $policySets.Items | Where-Object Name -eq $policySetName
if ([string]::IsNullOrEmpty($policySet))
{
    Write-Output "Policy Set named ${policySetName} does not exist"
    return
}
$policies = GetPoliciesInPolicySet $customerid $siteid $policySet.policySetGuid $bearerToken

if ([string]::IsNullOrEmpty($policies.Items))
{
    Write-Output "There is no policies in ${policySetName}"
    return
}
$policyGuids = ($policies.Items | Select-Object PolicyGuid).PolicyGuid 
$policyPriorityOrderBody = $policyGuids | Sort | ConvertTo-Json
SetPolicyPriorities $customerid $siteid $policySet.policySetGuid $bearerToken $policyPriorityOrderBody

<!--NeedCopy-->

Set new priority for polices in a policy set from your site using C# code

Learn from the following example to set new priority for polices in a policy set within your Citrix DaaS site using any C# code.

public static async Task<string> SetPolicyPriorities(
    string customerid,
    string siteid,
    string policySetGuid,
    string bearerToken,
    IList<string> policyGuids)
{
    var requestUri = string.Format("https://api.cloud.com/cvad/manage/gpo/policyPriorities?policySetGuid={0}", policySetGuid);
    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("Authorization", $"CWSAuth Bearer={bearerToken}");

        var jsonBody = JsonConvert.SerializeObject(policyGuids, 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-->

Set new priority for polices in a policy set from your site using Python

Learn from the following example to set new priority for polices in a policy set within your Citrix DaaS site using Python.

import json
import requests

def set_policy_priorities(bearerToken, customerid, siteid, policySetGuid):
    request_uri = "https://api.cloud.com/cvad/manage/gpo/policyPriorities?policySetGuid={0}".format(policySetGuid)
    headers = {
                'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
                'Citrix-CustomerId': customerid,
                'Citrix-InstanceId': siteid,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
              }
    payload = json.dumps([
        "de496042...",
        "730b7cfe..."
    ])

    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 set new priority for polices in a policy set in Citrix DaaS