How to move or copy policies to a policy set in Citrix DaaS
Use REST APIs to move or copy policies to 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 move or copy policies to 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. - Get
policySetGuid
from How to get all policy sets API. - Invoke the API described in this document from a client host or from the API exploration tab to move or copy policies to a policy set.
Move or copy policies to a policy set in Citrix DaaS using any REST API tool
Learn from the following example to move policies from one policy set to another policy set in your Citrix DaaS site using any REST API tool.
Request
POST https://api.cloud.com/cvad/manage/gpo/policies/policies/$move?toPolicySet={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..."
]
<!--NeedCopy-->
Response
HTTP/1.1 204 NoContent
citrix-transactionid: 22bff646...
content-Length: 0
content-Type: application/json; charset=utf-8
date: "Wed,08 Nov 2023 02:34:55 GMT"
<!--NeedCopy-->
Learn from the following example to copy policies from one policy set to another policy set in your Citrix DaaS site using any REST API tool.
Request
POST https://api.cloud.com/cvad/manage/gpo/policies/policies/$copy?withFilters=false 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
{
"policyGuids": [
"730b7cfe..."
],
"toPolicySets": [
"e5408e82..."
]
}
<!--NeedCopy-->
Response
HTTP/1.1 204 NoContent
citrix-transactionid: aaa7c3e7...
content-Length: 0
content-Type: application/json; charset=utf-8
date: "Wed,08 Nov 2023 02:39:00 GMT "
<!--NeedCopy-->
Move or copy policies to a policy set in Citrix DaaS using PowerShell
Learn from the following example to move or copy policies to a policy set in your Citrix DaaS site using PowerShell code.
function MovePoliciesToPolicySet {
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/$move?toPolicySet={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
}
function CopyPoliciesToPolicySet {
param (
[Parameter(Mandatory=$true)]
[string] $customerid,
[Parameter(Mandatory=$true)]
[string] $siteid,
[Parameter(Mandatory=$true)]
[bool] $withFilters,
[Parameter(Mandatory=$true)]
[string] $bearerToken,
[Parameter(Mandatory=$true)]
[string] $body
)
$requestUri = [string]::Format('https://api.cloud.com/cvad/manage/gpo/policies/$copy?withFilters={0}', $withFilters)
$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.."
$movedPolicyGuid = "de496042..."
$copiedPolicyGuid = "730b7cfe..."
$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
}
$policiesMovedBody = @"
[
"$movedPolicyGuid"
]
"@
$policySetGuid = $policySet.policySetGuid
MovePoliciesToPolicySet $customerid $siteid $policySetGuid $bearerToken $policiesMovedBody
$policiesCopiedBody = @"
{
"policyGuids": [
"$copiedPolicyGuid"
],
"toPolicySets": [
"$policySetGuid"
]
}
"@
CopyPoliciesToPolicySet $customerid $siteid $false $bearerToken $policiesCopiedBody
<!--NeedCopy-->
Move or copy policies to a policy set in Citrix DaaS using C# code
Learn from the following example to move or copy policies to a policy set in your Citrix DaaS site using C# code.
public static async Task<string> MovePoliciesToPolicySet(
string customerid,
string siteid,
string policySetGuid,
string bearerToken,
IList<string> policyGuids)
{
var requestUri = string.Format("https://api.cloud.com/cvad/manage/gpo/policies/$move?toPolicySet={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;
}
}
public static async Task<string> CopyPoliciesToPolicySet(
string customerid,
string siteid,
bool withFilters,
string bearerToken,
CopyPoliciesRequest model)
{
var requestUri = string.Format("https://api.cloud.com/cvad/manage/gpo/policies/$copy?withFilters={0}", withFilters);
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-->
Move or copy policies to a policy set in Citrix DaaS using Python
Learn from the following example to move or copy policies to a policy set in your Citrix DaaS site using Python.
import json
import requests
def move_policiese_to_policy_set(bearerToken, customerid, siteid, policySetGuid):
request_uri = "https://api.cloud.com/cvad/manage/gpo/policies/$move?toPolicySet={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..."
])
response = requests.post(request_uri, headers = headers, verify = False, data = payload)
return response
def copy_policiese_to_policy_set(bearerToken, customerid, siteid, withFilters):
request_uri = "https://api.cloud.com/cvad/manage/gpo/policies/$copy?withFilters={0}".format(withFilters)
headers = {
'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
'Citrix-CustomerId': customerid,
'Citrix-InstanceId': siteid,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
payload = json.dumps({
"policyGuids": [
"730b7cfe..."
],
"toPolicySets": [
"e5408e82..."
]
})
response = requests.post(request_uri, headers = headers, verify = False, data = payload)
return response
<!--NeedCopy-->
In this article
- Prerequisites to move or copy policies to a policy set in Citrix DaaS
- Move or copy policies to a policy set in Citrix DaaS using any REST API tool
- Move or copy policies to a policy set in Citrix DaaS using PowerShell
- Move or copy policies to a policy set in Citrix DaaS using C# code
- Move or copy policies to a policy set in Citrix DaaS using Python