Public/Curanet/Invoicing/Get-CuranetInvoice.ps1
function Get-CuranetInvoice() { Param( [Parameter(Mandatory)] [ValidateSet("3370", "3850")] [string]$Account, [string]$InvoiceID ) 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 { if($InvoiceID) { $Invoices = (Invoke-WebRequest -Uri "https://api.curanet.dk/invoicing/v1/Invoices/$($InvoiceID)" -Headers $AuthorizationHeader -UseBasicParsing -Method GET).Content | ConvertFrom-Json } else { $Invoices = (Invoke-WebRequest -Uri "https://api.curanet.dk/invoicing/v1/Invoices" -Headers $AuthorizationHeader -UseBasicParsing -Method GET).Content | ConvertFrom-Json } } catch { throw "Failed to retreive invoices from Curanet $($Account) API: $_" } return $Invoices } |