Public/Complete-ConnectorSyncSessionOperation.ps1

function Complete-ConnectorSyncSessionOperation {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $Operation
    )

    process {
        if ($PSCmdlet.ShouldProcess($Operation.Id ?? "New object", $Operation.OperationType)) {
            if ($Operation.OperationType -eq "Create") {
                $Result = Invoke-RestMethod `
                    -Uri "$($Script:APIRoot)data" `
                    -Method Post `
                    -ContentType "application/json" `
                    -Body ($Operation.ConnectorObject | ConvertTo-Json -Depth 30) `
                    -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile)
            }
            elseif ($Operation.OperationType -eq "Update") {
                $Result = Invoke-RestMethod `
                    -Uri "$($Script:APIRoot)data/$($Operation.Id)" `
                    -Method Patch `
                    -ContentType "application/json" `
                    -Body ($Operation.ConnectorObject | ConvertTo-Json -Depth 30) `
                    -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile)
            }
            elseif ($Operation.OperationType -eq "Delete") {
                $Result = Invoke-RestMethod `
                    -Uri "$($Script:APIRoot)data/$($Operation.Id)" `
                    -Method Delete `
                    -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile)
            }
            else {
                throw "Unsupported operation type: '$($Operation.OperationType)'"
            }
        }
    }
}