functions/Invoke-RGRequest.ps1
|
function invoke-RGRequest { param ( [uri] $Uri, [string] $Method, [PSCredential] $Credential, [hashtable] $Body ) if ([string]::IsNullOrEmpty($Method)) { $Method = 'GET' } if ([string]::IsNullOrEmpty($Uri.OriginalString)) { $Uri = $script:RedmineRootUri } if ($null -eq $Credential) { $Credential = $script:RedmineCredential } # $RootObject = (((($script:RedmineUri -split '/' |Select-Object -Last 1) -split '\?') |Select-Object -First 1) -replace '.json', '') $params = @{} $params.Body = ($Body | ConvertTo-Json) $params.Headers = @{"Content-Type" = "application/json; charset=utf-8" } $params.Credential = $Credential $params.Method = $Method $params.Uri = $Uri write-host $Uri $result = Invoke-WebRequest @params #write-host $result try { return ($result.Content | ConvertFrom-Json) } catch { Write-Host $Body Write-Host $result } } |