How to create a policy set in Citrix DaaS
Use REST APIs to create 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 create a policy set in Citrix DaaS
- 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. - Update
policySetGuid
of the delivery group from How to update a delivery group API. - Invoke the API described in this document from a client host or from the API exploration tab to create a policy set.
Create a policy set in Citrix DaaS using any REST API tool
Learn from the following example to create a policy set in your Citrix DaaS site using any REST API tool.
Request
POST https://api.cloud.com/cvad/manage/gpo/policySets 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
{
"policySetType": "DeliveryGroupPolicies",
"name": "PS01",
"description": "PS01",
"scopes": []
}
<!--NeedCopy-->
Response
HTTP/1.1 200 OK
citrix-transactionid: b231f5e2...
content-Length: 183
content-Type: application/json; charset=utf-8
date: "Thu,02 Nov 2023 06:46:35 GMT"
{
"policySetGuid": "ebc10e7d...",
"policySetType": "DeliveryGroupPolicies",
"name": "PS01",
"description": "PS01",
"policyCount": 0,
"scopes": [
"All"
],
"isAssigned": false
}
<!--NeedCopy-->
Learn from the following example to create a policy in the policy set in your Citrix DaaS site using any REST API tool.
Request
POST https://api.cloud.com/cvad/manage/gpo/policies?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
{
"name": "P01",
"isEnabled": true,
"description": "P01",
"settings": [
{
"settingName": "WatermarkTransparency",
"useDefault": true,
"settingValue": "true"
}
],
"filters": [
{
"filterType": "ClientName",
"isAllowed": true,
"isEnabled": true,
"filterData": "Client-Name1"
}
]
}
<!--NeedCopy-->
Response
HTTP/1.1 200 OK
citrix-transactionid: 4bca3b5b...
content-Length: 579
content-Type: application/json; charset=utf-8
date: "Thu,02 Nov 2023 07:24:19 GMT"
{
"policySetGuid": "ce682aab...",
"policyGuid": "a90cb09c...",
"policyName": "P01",
"priority": 1,
"isEnabled": true,
"description": "P01",
"settings": [
{
"policyGuid": "a90cb09c...",
"settingGuid": "b046c589...",
"settingName": "WatermarkTransparency",
"useDefault": true,
"settingValue": null
}
],
"filters": [
{
"policyGuid": "a90cb09c...",
"filterType": "ClientName",
"filterGuid": "84942f72...",
"isAllowed": true,
"isEnabled": true,
"filterData": "Client-Name1"
}
]
}
<!--NeedCopy-->
Learn from the following example to attach the policy set to a delivery group in your Citrix DaaS site using any REST API tool.
Request
PATCH https://api.cloud.com/cvad/manage/DeliveryGroups/{nameOrId} 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
{
"PolicySetGuid": "ce682aab..."
}
<!--NeedCopy-->
Response
HTTP/1.1 204 NoContent
citrix-transactionid: 0d2bbc2b...
content-Type: application/json; charset=utf-8
date: "Thu,02 Nov 2023 07:36:45 GMT"
<!--NeedCopy-->
Create a policy set in Citrix DaaS using PowerShell
Learn from the following example to create a policy set in your Citrix DaaS site using PowerShell code.
function CreatePolicySet {
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/gpo/policySets"
$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
}
function CreatePolicyInPolicySet {
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/policies?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.."
$deliveryGroupName = "DG01"
$policySetCreateModel = @"
{
"policySetType": "DeliveryGroupPolicies",
"name": "PS01",
"description": "PS01",
"scopes": []
}
"@
$policyCreateModel = @"
{
"name": "P01",
"isEnabled": true,
"description": "P01",
"settings": [
{
"settingName": "WatermarkTransparency",
"useDefault": true,
"settingValue": "true"
}
],
"filters": [
{
"filterType": "ClientName",
"isAllowed": true,
"isEnabled": true,
"filterData": "Client-Name1"
}
]
}
"@
$response = CreatePolicySet $customerid $siteid $bearerToken $policySetCreateModel
$policySetGuid = $response.PolicySetGuid
CreatePolicyInPolicySet $customerid $siteid $policySetGuid $bearerToken $policyCreateModel
$deliveryGroupUpdateModel = @"
{
"PolicySetGuid": "$policySetGuid"
}
"@
$deliveryGroups = GetDeliveryGroups $customerid $siteid $bearerToken
$deliveryGroups.Items | Where-Object Name -eq $deliveryGroupName | ForEach-Object {
PatchDeliveryGroup $customerid $siteid $_.Id $bearerToken $deliveryGroupUpdateModel
}
<!--NeedCopy-->
Create a policy set in Citrix DaaS using C# code
Learn from the following example to create a policy set in your Citrix DaaS site using C# code.
public static async Task<string> CreatePolicySet(
string customerid,
string siteid,
string bearerToken,
PolicySetRequest model)
{
var requestUri = "https://api.cloud.com/cvad/manage/gpo/policySets";
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(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;
}
}
public static async Task<string> CreatePolicyInPolicySet(
string customerid,
string siteid,
string policySetGuid,
string bearerToken,
PolicyRequest model)
{
var requestUri = string.Format("https://api.cloud.com/cvad/manage/gpo/policies?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(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-->
Create a policy set in Citrix DaaS using Python
Learn from the following example to create a policy set in your Citrix DaaS site using Python.
import json
import requests
def create_policy_set(bearerToken, customerid, siteid):
request_uri = "https://api.cloud.com/cvad/manage/gpo/policySets"
headers = {
'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
'Citrix-CustomerId': customerid,
'Citrix-InstanceId': siteid,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
payload = json.dumps({
"policySetType": "DeliveryGroupPolicies",
"name": "PS01",
"description": "PS01",
"scopes": []
})
response = requests.post(request_uri, headers = headers, verify = False, data = payload)
return response.json()
def create_policy_in_policy_set(bearerToken, customerid, siteid, policySetGuid):
request_uri = "https://api.cloud.com/cvad/manage/gpo/policies?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({
"name": "P01",
"isEnabled": True,
"description": "P01",
"settings": [
{
"settingName": "WatermarkTransparency",
"useDefault": True,
"settingValue": "true"
}
],
"filters": [
{
"filterType": "ClientName",
"isAllowed": True,
"isEnabled": True,
"filterData": "Client-Name1"
}
]
})
response = requests.post(request_uri, headers = headers, verify = False, data = payload)
return response.json()
<!--NeedCopy-->