Public/Curanet/Get-CuranetCustomer.ps1
function Get-CuranetCustomer() { Param( [Parameter()] [string]$CustomerName, [Parameter()] [string]$CustomerId, [Parameter(Mandatory)] [ValidateSet("3370", "3850")] [string]$Account ) if( ($null -eq (Get-Variable -Name "$($Account)AccessTokenExpire" -Scope Global -ValueOnly -ErrorAction SilentlyContinue)) -or ((Get-Date) -gt (Get-Variable -Name "$($Account)AccessTokenExpire" -Scope Global -ValueOnly -ErrorAction SilentlyContinue)) ) { Get-CuranetAccessToken -Account $Account } $AccessToken = (Get-Variable -Name "$($Account)AccessToken" -Scope Global -ValueOnly -ErrorAction SilentlyContinue).access_token $AuthorizationHeader = @{ Authorization="Bearer $AccessToken" } try { $Customers = (Invoke-WebRequest -Uri "https://api.curanet.dk/customers/v1/Customers?itemsPerPage=9999" -Headers $AuthorizationHeader -UseBasicParsing -Method GET).Content | ConvertFrom-Json } catch { throw "Failed to retreive customers from Curanet $($Account) API: $_" } if($CustomerName) { $Customers = $Customers | Where-Object { $_.companyName -eq $CustomerName } } elseif ($CustomerId) { $Customers = $Customers | Where-Object { $_.ID -eq $CustomerId } } return $Customers } |