This article describes how to use the CloudAnwyhere SDK to automate the configuration of CloudAnywhere if you have a large number of customers to manage or if your customers are created in an external system and you want to automate the configuration in CloudAnywhere.

In the following example, a hosted provider had to manage a large number of schools.
When they create a new school in their management platform, an organizational unit is automatically created in their mutualized Active Directory.
The goal of this piece of code is to automate the configuration in CloudAnywhere in order to synchronize the specific organizational unit with a given tenant in Office 365.

CASDK sdk = new CASDK();//////////////////////////////////////
//   Create your schools
///////////////////////////////////////
CreateSchool(“School 1”, “OU=school1,DC=mydomain,DC=local”, “school1.com”, “admincloud@school1.com“, “adminpwd”, “school1:studentpack”);
CreateSchool(“School 2”, “OU=school2,DC=mydomain,DC=local”, “school2.com”, “admincloud@school2.com“, “adminpwd”, “school2:studentpack”);
CreateSchool(“School 3”, “OU=school2,DC=mydomain,DC=local”, “school3.com”, “admincloud@school3.com“, “adminpwd”, “school3:studentpack”);
CreateSchool(“School 4”, “OU=school2,DC=mydomain,DC=local”, “school4.com”, “admincloud@school4.com“, “adminpwd”, “school4:studentpack”);
//////////////////////////////////////
// Pull the source and targets
///////////////////////////////////////
SourceAgents = sdk.GetSourceAgents();
// Pull source connectors. You can even select the connector you want to sync
foreach (SourceAgent agent in SourceAgents)
{
sdk.PullSource(agent);
}

// Mandatory, don’t forget to call these 2 functions
sdk.SyncGroupMembership();
sdk.EndSynchronization();

TargetAgents = sdk.GetTargetAgents();
// Pull target connectors
foreach (CloudAgents agent in TargetAgents)
{
sdk.PullTarget(agent);
}
//////////////////////////////////////
//   Do the provisioning
///////////////////////////////////////
foreach (SourceAgent agent in SourceAgents)
{
sdk.Reconcile(agent);
}
// Mandatory, don’t forget to call this functions
sdk.EndReconciliation();

For simplicity of reading, the code of CreateSchool isn’t provided.
However, it looks like:

Guid domainID = sdk.CreateSourceConnector(schoolName, SOURCEID.ADSOURCE);
SourceDomain domain = new SourceDomain();
domain.ID = domainID;
domain.DN = “DC=mydomain,DC=local”;
domain.Name = “mydomain.local”;
domain.NetbiosName = “mydomain”;
domain.DisablePulling = false;
domain.Server = “dcname”;
domain.Port = “389”;
domain.UserName = “Account_With_Read_Permission”;
domain.Password = Helpers.CryptPassword(“Thepassword”);
sdk.SaveSourceConnectorSettings(domain);