DEV Community

edreux
edreux

Posted on

Automate Microsoft 365 Migrations with Cloudiway Rest Apis

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

Image description
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

Image description

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.

Image description

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   
    }
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

Further reading

Full rest api documentation is available here.

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (1)

Collapse
 
jaloplo profile image
Jaime López

I don't see where Microsoft 365 is involved here. Can you add an example for migrating a SharePoint Online site between two tenants???

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay