<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: edreux</title>
    <description>The latest articles on Forem by edreux (@edreux).</description>
    <link>https://forem.com/edreux</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1365728%2Ff40d1c6a-01e7-46c0-b0f9-050c95d98f36.png</url>
      <title>Forem: edreux</title>
      <link>https://forem.com/edreux</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/edreux"/>
    <language>en</language>
    <item>
      <title>Automate Microsoft 365 Migrations with Cloudiway Rest Apis</title>
      <dc:creator>edreux</dc:creator>
      <pubDate>Tue, 19 Mar 2024 14:48:59 +0000</pubDate>
      <link>https://forem.com/edreux/automate-microsoft-365-migrations-with-cloudiway-rest-apis-4aoe</link>
      <guid>https://forem.com/edreux/automate-microsoft-365-migrations-with-cloudiway-rest-apis-4aoe</guid>
      <description>&lt;p&gt;Cloudiway is a Cloud migration platform  that allows to &lt;a href="https://cloudiway.com/solutions/"&gt;migrate your data between tenants&lt;/a&gt; (Mailboxes, Drives, Teams, sites ).&lt;/p&gt;

&lt;p&gt;This article explains how to use the Cloudiway Rest Apis to automate the migration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to create an account in the &lt;a href="//Https://portal.cloudiway.com"&gt;Cloudiway platform &lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Authentication is done using a PAT (Personal Access Token). You need to create a PAT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Procedure to create a PAT:&lt;/strong&gt;&lt;br&gt;
In the upper right, click on ACCOUNT then API&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8eto3nsho1br96naxg0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8eto3nsho1br96naxg0c.png" alt="Image description" width="242" height="530"&gt;&lt;/a&gt;&lt;br&gt;
Click on Create a new Token and fill the information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give a name to your PAT&lt;/li&gt;
&lt;li&gt;Define an expiration date&lt;/li&gt;
&lt;li&gt;Define the CRUD operations that are authorized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2zieofkl1921ymj7w6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2zieofkl1921ymj7w6e.png" alt="Image description" width="566" height="912"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Create and save your PAT for the next steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create your first application:&lt;/strong&gt;&lt;br&gt;
The Swagger definition of the Cloudiway APIs can be found here: &lt;a href="https://api-production.cloudiway.com/index.html"&gt;Swagger definitions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Set the project that you wish to access.&lt;br&gt;
You need to define your project ID. &lt;br&gt;
In the swagger URL, login ( Click on Authorize and paste your PAT).&lt;br&gt;
Then call the /projects endpoint and note the projectID of your choice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqahpb837iashv5w549cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqahpb837iashv5w549cl.png" alt="Image description" width="630" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are now ready to programmatically manipulate the Cloudiway platform:&lt;br&gt;
You global settings will look like this:&lt;br&gt;
$global:HOSTURL = '&lt;a href="https://api-production.cloudiway.com"&gt;https://api-production.cloudiway.com&lt;/a&gt;'&lt;br&gt;
$userId = '&lt;a href="mailto:Name@cloudiway.com"&gt;Name@cloudiway.com&lt;/a&gt;' #Your Login&lt;br&gt;
$userPass = 'YourPassword' #Your Password&lt;/p&gt;
&lt;h1&gt;
  
  
  Login
&lt;/h1&gt;

&lt;p&gt;$global:TOKEN = 'Your PAT'&lt;/p&gt;

&lt;p&gt;Identify the project you want to work on and insert the projectId here&lt;br&gt;
$global:PROJID = 1234&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a user programmatically
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $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   
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Start the migration programmatically
&lt;/h2&gt;

&lt;p&gt;Let's define a job class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cloudiway.com/documentation/restapis-documentation/"&gt;Full rest api documentation is available here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>teams</category>
      <category>migration</category>
      <category>sharepoint</category>
      <category>microsoft365</category>
    </item>
  </channel>
</rss>
