public/Get-FootballFixtureCornerCount.ps1

function Get-FootballFixtureCornerCount {
    <#
        .EXAMPLE
            Get-FootballFixtureCornerCount -Header $Headers -Token $Token -Competition jpn-jleague -Date 2025-02-26 -Path C:\sportsmonk
         
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

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

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

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $PathToResults = "$Path\sportsmonk-results\$Competition\$Date\$Competition-$Date.csv"
            $PathToResultsExists = Test-Path -Path $PathToResults

            if ($PathToResultsExists) {

                $FixtureResults = Import-Csv -Path $PathToResults
                foreach ($Fixture in $FixtureResults) {

                    $TypeUri = "https://api.sportmonks.com/v3/football/fixtures/$($Fixture.Fixture_id)?api_token=$Token&include=scores;participants;statistics.type;events"
                    $TypeResponse = Invoke-RestMethod $TypeUri -Method 'GET' -Headers $Header
                    $ResponseData = $($TypeResponse.data)
                    $FixtureStats = $($ResponseData.statistics)

                    $FixtureCornerStatistics = $FixtureStats | Where-Object {$_.type_id -eq 34}
                    $FixtureHomeCornerStatistics = $FixtureCornerStatistics | Where-Object {$_.location -eq 'home'}
                    $FixtureAwayCornerStatistics = $FixtureCornerStatistics | Where-Object {$_.location -eq 'away'}

                    $FixtureHomeCornerData = $($FixtureHomeCornerStatistics.data)
                    $FixtureAwayCornerData = $($FixtureAwayCornerStatistics.data)

                    $PSObject = [PSCustomObject]@{
                        FixtureId = $($ResponseData.id)
                        FixtureName = $($ResponseData.name)
                        FixtureHomeCorner = $($FixtureHomeCornerData.value)
                        FixtureAwayCorner = $($FixtureAwayCornerData.value)
                        ResultInfo = $($ResponseData.result_info)
                        HomeScore = $($Fixture.HomeScore)
                        AwayScore = $($Fixture.AwayScore)
                    }

                    $PSObject

                } # foreach

            } # if
        }
        catch {

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

        } # trycatch

    } # process

} # function