public/Get-FixtureList.ps1

function Get-FixtureList {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateSet('australia','europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')]
        [string]$Continent,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$DateRange,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$Header,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {
            
            # Initialize variables

            if ($($PSBoundParameters.ContainsKey('Date')) -and !$($PSBoundParameters.ContainsKey('DateRange'))) {

                $BaseUri = "https://api.sportmonks.com/v3/football/fixtures/date/$Date"

            } # if

            if ($($PSBoundParameters.ContainsKey('DateRange')) -and !$($PSBoundParameters.ContainsKey('Date'))) {

                $BaseUri = "https://api.sportmonks.com/v3/football/fixtures/between/$DateRange"

            } # if


            $AllFixtures = @()

            # Loop through all pages using the next_page link
            $count = 0
            do {

                if ($Count -lt 1) {

                    $UriToUse = $BaseUri+'?api_token='+$Token

                }
                else {

                    $UriToUse = $BaseUri+'&api_token='+$Token

                }

                # Fetch current page
                $Response = Invoke-RestMethod -Uri $UriToUse -Method 'GET' -Headers $Header

                # Add fixtures from the current page to the collection
                $AllFixtures += $Response.data

                # Update the BaseUri to the next page if available
                $BaseUri = $Response.pagination.next_page
                $HasMorePages = $Response.pagination.has_more
                $Count++

            } while ($HasMorePages)

            Select-FootballCompetitionFixtureList -Continent $Continent -FixtureList $AllFixtures

        }
        catch {

            throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function