Public/Invoke-Connector.ps1

<#
.SYNOPSIS
Executes the SuccessFactors connector to retrieve and process data from multiple resource types.

.DESCRIPTION
Connects to SuccessFactors and retrieves data from predefined resource types including users, employees, jobs, cost centers, positions, departments, companies, locations, job functions, persons, and personal information. Processes each resource and builds connector objects for further processing. Each resource type is mapped to its corresponding unique identifier field.

.PARAMETER ConnectorConfiguration
The configuration object containing SuccessFactors connection details and authentication credentials.

.OUTPUTS
System.Object - Connector objects with external ID and processed resource data.

.NOTES
Retrieves the following resource types with their unique ID fields:
- User (userId), EmpEmployment (employmentId), EmpJob (jobinfoId)
- FOCostCenter, Position, FODepartment, FOCompany, FOLocation, FOJobFunction (all use externalCode)
- PerPerson, PerPersonal (both use personIdExternal)

Failed items are logged but do not halt processing.

Future enhancement: Resource type definitions and ID field mappings should be moved to ConnectorConfiguration for tenant-specific customization.
#>

function Invoke-Connector {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $ConnectorConfiguration
    )

    # Connect to SuccessFactors and retrieve access token.
    Connect-SF -ConnectorConfiguration $ConnectorConfiguration
    Send-ConnectorLog "Connected successfully" | out-null

    # Define the resource types to retrieve from SuccessFactors.
    # NOTE: Resource type definitions could be moved to ConnectorConfiguration for tenant-specific customization.
    $resourceTypes = @(
        @{Type='User'; IdField='userId'},
        @{Type='EmpEmployment'; IdField='employmentId'},
        @{Type='EmpJob'; IdField='jobinfoId'},
        @{Type='FOCostCenter'; IdField='externalCode'},
        @{Type='Position'; IdField='externalCode'},
        @{Type='FODepartment'; IdField='externalCode'; QueryString='?$expand=parentNav,headOfUnitNav'},
        @{Type='FOCompany'; IdField='externalCode'},
        @{Type='FOLocation'; IdField='externalCode'; QueryString='?$expand=addressNavDEFLT'},
        @{Type='FOJobFunction'; IdField='externalCode'; QueryString='?$expand=parentFunctionCodeNav'},
        @{Type='PerPerson'; IdField='personIdExternal'},
        @{Type='PerPersonal'; IdField='personIdExternal'}
    )

    # Retrieve and process each resource type.
    $resourceTypes | ForEach-Object {
        $resourceType = $_.Type
        $idField = $_.IdField
        if ($null -ne $_.QueryString) {
            $queryString = $_.QueryString
        }
        else {
            $queryString = $null
        }
        
        $count = 0
        Invoke-SFRestMethod -Resource $resourceType -BaseUrl $ConnectorConfiguration.configuration.baseurl -QueryString $queryString | ForEach-Object {
            try {
                $idValue = $_.$idField
                Build-ConnectorObject -ExternalId $idValue -Data $_ -ObjectType $resourceType
                $count += 1
            } 
            catch {
                $idValue = $_.$idField
                Send-ConnectorLog "Failed to process $resourceType object '$idValue': $_" | Out-Null
            }
        }

        Send-ConnectorLog "Retrieved $count resources of type $resourceType" | out-null
    }
}