Citrix Virtual Apps and Desktops REST APIs

How to add a machine to a machine catalog in Citrix Virtual Apps and Desktops

Use REST APIs to add a machine to a machine catalog in your Citrix Virtual Apps and Desktops 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 add a machine to a machine catalog in Citrix Virtual Apps and Desktops

Add a machine to a machine catalog in your site using any REST API tool

Learn from the following example to add a machine to a machine catalog in your Citrix Virtual Apps and Desktops site using any REST API tool.

Request

POST https://[DdcServerAddress]/cvad/manage/MachineCatalogs/{nameOrId}/Machines 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

{
    "MachineName": "ORCHPERFS2\\Ops2Machine-0001"
}
<!--NeedCopy-->

Response

HTTP/1.1 200 OK
citrix-transactionid: 3a69984b...
content-Length: 547
content-Type: application/json; charset=utf-8
date: "Thu, 17 Sep 2020 06:39:21 GMT"

{
    "Id": "5b4f9c91...",
    "Type": "AddMachineCatalogMachine",
    "OverallProgressPercent": 0,
    "IsCancellable": true,
    "Parameters": [
        {
            "Name": "NameOrId",
            "Value": "CVAD_APIs_Physical_MC"
        }
    ],
    "SubJobs": [],
    "Status": "NotStarted",
    "ResultLocation": null,
    "ErrorString": null,
    "ErrorCode": "Unknown",
    "ErrorParameters": [],
    "CreationTime": "2022-02-09T07:22:04.254+00:00",
    "FormattedCreationTime": "2022-02-09T07:22:04Z",
    "StartTime": "0001-01-01T00:00:00+00:00",
    "FormattedStartTime": "0001-01-01T00:00:00Z",
    "EndTime": "0001-01-01T00:00:00+00:00",
    "FormattedEndTime": "0001-01-01T00:00:00Z"
}
<!--NeedCopy-->

Add a machine to a machine catalog in your site using PowerShell

Learn from the following example to add a machine to a machine catalog in your Citrix Virtual Apps and Desktops site using any PowerShell code.

function AddMachineToMachineCatalog {
    param (
        [Parameter(Mandatory=$true)]
        [string] $customerid,
        [Parameter(Mandatory=$true)]
        [string] $siteid,
        [Parameter(Mandatory=$true)]
        [string] $nameOrId,
        [Parameter(Mandatory=$true)]
        [string] $bearerToken,
        [Parameter(Mandatory=$true)]
        [string] $body
    )
    $requestUri = [string]::Format("https://[DdcServerAddress]/cvad/manage/MachineCatalogs/{0}/Machines", $nameOrId)
    $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"
$nameOrId = "CVAD_APIs_Physical_MC"
$bearerToken = "ey1.."
$body = @{
        "MachineName" = "ORCHPERFS2\\Ops2Machine-0001"
    }
$response = AddMachineToMachineCatalog $customerid $siteid $nameOrId $bearerToken (ConvertTo-Json $body)
<!--NeedCopy-->

Add a machine to a machine catalog in your site using C# code

Learn from the following example to add a machine to a machine catalog in your Citrix Virtual Apps and Desktops site using C# code.

public static async Task<string> AddMachineToMachineCatalog(
    string customerid,
    string siteid,
    string nameOrId,
    string bearerToken,
    AddMachineToMachineCatalogDetailRequestModel model)
{
    var requestUri = string.Format("https://[DdcServerAddress]/cvad/manage/MachineCatalogs/{0}/Machines", nameOrId);
    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 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-->

Add a machine to a machine catalog in your site using Python

Learn from the following example to add a machine to a machine catalog in your Citrix Virtual Apps and Desktops site using Python.

import requests 

def add_machine_to_machine_catalog(bearerToken, customerid, siteid, nameOrId):
    request_uri = "https://[DdcServerAddress]/cvad/manage/MachineCatalogs/{0}/Machines".format(nameOrId)
    headers = {
                'Authorization': 'CWSAuth Bearer %s' %bearerToken,
                'Citrix-CustomerId': customerid,
                'Citrix-InstanceId': siteid,
                'Content-Type': 'application/json',
                'Accept': 'application/json'
              }
    payload = json.dumps({
        "MachineName": "ORCHPERFS2\\Ops2Machine-0001"
    })

    response = requests.post(request_uri, headers = headers, verify = False, data = payload)

    return response.json()
<!--NeedCopy-->
Resources
Citrix Virtual Apps and Desktops REST APIs OpenAPI Specification
Copy Download
How to add a machine to a machine catalog in Citrix Virtual Apps and Desktops