Cloudiway is a Cloud migration platform that allows to migrate your data between tenants (Mailboxes, Drives, Teams, sites ).
This article explains how to use the Cloudiway Rest Apis to automate the migration.
Prerequisites
- You need to create an account in the Cloudiway platform .
- Authentication is done using a PAT (Personal Access Token). You need to create a PAT
Procedure to create a PAT:
In the upper right, click on ACCOUNT then API
Click on Create a new Token and fill the information:
- Give a name to your PAT
- Define an expiration date
- Define the CRUD operations that are authorized
Click on Create and save your PAT for the next steps.
Create your first application:
The Swagger definition of the Cloudiway APIs can be found here: Swagger definitions
Set the project that you wish to access.
You need to define your project ID.
In the swagger URL, login ( Click on Authorize and paste your PAT).
Then call the /projects endpoint and note the projectID of your choice.
You are now ready to programmatically manipulate the Cloudiway platform:
You global settings will look like this:
$global:HOSTURL = 'https://api-production.cloudiway.com'
$userId = 'Name@cloudiway.com' #Your Login
$userPass = 'YourPassword' #Your Password
Login
$global:TOKEN = 'Your PAT'
Identify the project you want to work on and insert the projectId here
$global:PROJID = 1234
Create a user programmatically
$FirstName = "Test"
$lastName = "User"
$SourcePoolId = 1
$TargetPoolId = 2
$SourceEmail = "user@source.com"
$TargetEmail = "user@target.com"
$TargetRecipientType = 1 #1 = onedrive, 2= sharepoint
$TargetChannelName = "" #not used
$TargetFolder= "" #not used
$TargetLibrary= "" #not used
$this.TargetSiteName= "" #not used
function GetHeader(){
$Header = @{
"accept" = "*/*"
"Authorization" = "Bearer $global:BEARERTOKEN"
"projectId" = $global:PROJID
}
return $Header
}
function CreateFileUser(){
$BodyJson = @{
firstName = $this.FirstName
lastName = $this.LastName
sourcePoolId = $this.SourcePoolId
targetPoolId = $this.TargetPoolId
sourceEmail = $this.SourceEmail
targetEmail = $this.TargetEmail
targetRecipientType = $this.TargetRecipientType
targetChannelName = $this.TargetChannelName
targetFolder =$this.TargetFolder
targetLibrary = $this.TargetLibrary
targetSiteName=$this.TargetSiteName
}
$Parameters = @{
Method = "Post"
Uri = "$global:HOSTURL/ap1/File"
Headers = GetHeader
ContentType = "application/json"
Body = ($BodyJson | ConvertTo-Json)
}
$this.ResponseObject = Invoke-FrontAPI($Parameters) | ConvertFrom-Json
$this.ResponseJson = $this.ResponseObject | ConvertTo-Json -depth 100
}
Start the migration programmatically
Let's define a job class:
class Jobs
{
$ResponseObject
[String]$ResponseJson
[Int]$ProjectId
[Int]$BatchId
[Int]$JobType
[Int]$ProductType
[string]$StartJobsList
[string]$StopJobsList
StartJobs(){
$PType=$this.ProductType
$JType=$this.JobType
$Parameters = @{
Method = "Post"
Uri = "$global:HOSTURL/ap1/Jobs/StartJobs/$PType/$JType"
Headers = GetHeader
ContentType = "application/json"
Body = $this.StartJobsList
}
$this.ResponseObject = Invoke-FrontAPI($Parameters) | ConvertFrom-Json
$this.ResponseJson = $this.ResponseObject | ConvertTo-Json -depth 100
}
}
#Now we just have to call it:
function StartFileJobs{
param ([int]$JobType, [string]$ListIDs)
Write-Host "Start Jobs: " -ForegroundColor Yellow
$Jobs = [Jobs]::new()
$Jobs.StartJobsList= $ListIDs
$Jobs.ProductType = 6 #6 is for File, do not modify
$Jobs.JobType = $JobType
$Jobs.StartJobs()
Write-Host $Jobs.ResponseJson
}
Top comments (1)
I don't see where Microsoft 365 is involved here. Can you add an example for migrating a SharePoint Online site between two tenants???