Get-Token.ps1
<# .Synopsis The function returns scheme and token required for accessing API methods .DESCRIPTION The function returns a schema and token that is necessary for subsequent authentication of all API interface endpoint requests. All other module functions require the entry of the Token parameter in the "Schema Token" format. The AccessKey must be configured in the attendance system database. .PARAMETER URL Server API url .PARAMETER AccessKey The AccessKey to get an authentication token for accessing API data .EXAMPLE Get-Token -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 This command gets the authentication token for the specified accesskey #> function Get-Token { param( [Parameter(Mandatory = $true)] [string]$URL, [Parameter(Mandatory = $true)] [string]$AccessKey ) Process { $url = $url + "/Auth/Token" Write-Verbose -Message "Send request to API endpoint $URL with access key $AccessKey." $Token = Invoke-RestMethod -Method Post -Uri $url -Body @{ accesskey = $AccessKey } Write-Verbose -Message "Add property SchemeToken to return object." Add-Member -InputObject $Token -MemberType NoteProperty -Name SchemeToken -Value $($Token.Scheme + " " + $Token.Token) | Out-Null Write-Verbose -Message "Return object Token with SchemeToken: $($Token.SchemeToken)" $($Token) } } |