How to add a machine account to a catalog in Citrix DaaS
Use REST APIs to add an existing Active Directory machine account to the identity pool of an MCS machine catalog in your Citrix DaaS (formerly Citrix Virtual Apps and Desktops service) site.
This API is the REST equivalent of importing an externally-created computer account into the catalog’s identity pool, similar to what the New-AcctADAccount PowerShell cmdlet does when supplied with an existing AD account name. After the account is added, it becomes an Available account in the identity pool and can be consumed when provisioning a new machine in the catalog.
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 account to a catalog in Citrix DaaS
- Read the Get started with Citrix Cloud APIs section to ensure that you have the
bearer token. - Get
siteidfrom How to get site id API. - Get the
nameOrIdof the target machine catalog from How to get machine catalogs API. The catalog must haveProvisioningTypeset toMCS. - Make sure the Active Directory computer account to add already exists in AD and is not a member of any other machine catalog. The account name can be supplied in any of the following formats:
- Fully qualified DN, for example,
CN=MyComputer,OU=Computers,DC=MyDomain,DC=Com - UPN format, for example,
MyComputer@MyDomain.Com - Domain qualified, for example,
MyDomain\MyComputer
- Fully qualified DN, for example,
- Decide how to handle the machine account password:
- Set
ResetPasswordtotrue(the default) to let the site reset the account password to a random value. The administrator credential used for the call must have permission to reset the machine account password. - Set
ResetPasswordtofalseand supply the current account password inPassword, optionally with aPasswordFormatofPlainTextorBase64.
- Set
- Invoke the API described in this document from a client host or from the API exploration tab to add a machine account to the catalog.
Add a machine account to a catalog in your site using any REST API tool
Learn from the following example to import an existing AD computer account into an MCS catalog’s identity pool using any REST API tool.
For details on the request and response models, see the API specification.
Request
POST https://api.cloud.com/cvad/manage/MachineCatalogs/{nameOrId}/MachineAccounts 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
{
"ADAccountName": "MyDomain\\MyComputer",
"ResetPassword": true
}
<!--NeedCopy-->
If you do not want the site to reset the password, supply the current password and its format instead:
{
"ADAccountName": "MyDomain\\MyComputer",
"ResetPassword": false,
"Password": "Pa55w0rd",
"PasswordFormat": "PlainText"
}
<!--NeedCopy-->
Response
HTTP/1.1 200 OK
citrix-transactionid: 8b4f1c3a-...
content-Length: 230
content-Type: application/json; charset=utf-8
date: "Thu, 17 Sep 2020 06:39:21 GMT"
{
"SamName": "MyDomain\\MyComputer$",
"DnsName": "mycomputer.mydomain.com",
"Domain": "MyDomain",
"Sid": "S-1-5-21-...",
"Locked": false,
"State": "Available"
}
<!--NeedCopy-->
The response is a ProvisioningSchemeMachineAccountResponseModel describing the imported account. A State of Available indicates that the account is now part of the catalog’s identity pool and can be consumed by the next provisioning operation.
Add a machine account to a catalog in your site using PowerShell
Learn from the following example to import an existing AD computer account into an MCS catalog using PowerShell code.
function AddMachineAccountToCatalog {
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://api.cloud.com/cvad/manage/MachineCatalogs/{0}/MachineAccounts", $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_MCS_MC"
$bearerToken = "ey1.."
$body = @{
"ADAccountName" = "MyDomain\\MyComputer"
"ResetPassword" = $true
}
$response = AddMachineAccountToCatalog $customerId $siteId $nameOrId $bearerToken (ConvertTo-Json $body)
<!--NeedCopy-->
Add a machine account to a catalog in your site using C# code
Learn from the following example to import an existing AD computer account into an MCS catalog using C# code.
public static async Task<string> AddMachineAccountToCatalog(
string customerid,
string siteid,
string nameOrId,
string bearerToken,
MachineAccountRequestModel model)
{
var requestUri = string.Format("https://api.cloud.com/cvad/manage/MachineCatalogs/{0}/MachineAccounts", 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 account to a catalog in your site using Python
Learn from the following example to import an existing AD computer account into an MCS catalog using Python.
import requests
import json
def add_machine_account_to_catalog(bearerToken, customerid, siteid, nameOrId):
request_uri = "https://api.cloud.com/cvad/manage/MachineCatalogs/{0}/MachineAccounts".format(nameOrId)
headers = {
'Authorization': 'CWSAuth Bearer=%s' % bearerToken,
'Citrix-CustomerId': customerid,
'Citrix-InstanceId': siteid,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
payload = json.dumps({
"ADAccountName": "MyDomain\\MyComputer",
"ResetPassword": True
})
response = requests.post(request_uri, headers = headers, verify = False, data = payload)
return response.json()
<!--NeedCopy-->
Related APIs
- To list all the machine accounts that are currently associated with a catalog (along with their state), use
GET /MachineCatalogs/{nameOrId}/MachineAccounts. - To register a machine in a catalog after the AD account has been added, see How to add a machine to a machine catalog.
- To import many machine accounts in a single round trip, see How to use batch API to add machines to catalog.
In this article
- Prerequisites to add a machine account to a catalog in Citrix DaaS
- Add a machine account to a catalog in your site using any REST API tool
- Add a machine account to a catalog in your site using PowerShell
- Add a machine account to a catalog in your site using C# code
- Add a machine account to a catalog in your site using Python
- Related APIs