Skip to content

Commit

Permalink
- If the result is JSON you can enable converting it to a HashTable …
Browse files Browse the repository at this point in the history
…with the `Invoke-ARAHRequest -ConvertJsonAsHashtable` switch. This is needed in case of the error `Cannot convert the JSON string because it contains keys with different casing. Please use the -AsHashTable switch instead.`

 - File Downloads can be handled
  • Loading branch information
Callidus2000 committed Sep 29, 2023
1 parent 38ebef5 commit 10bdc51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ARAH/ARAH.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'ARAH.psm1'

# Version number of this module.
ModuleVersion = '1.3.7'
ModuleVersion = '1.3.8'

# ID used to uniquely identify this module
GUID = '5bf61bed-a3da-4550-949a-a869b8dc29c6'
Expand Down
3 changes: 3 additions & 0 deletions ARAH/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 1.3.8 (2023-09-08)
- If the result is JSON you can enable converting it to a HashTable with the `Invoke-ARAHRequest -ConvertJsonAsHashtable` switch. This is needed in case of the error `Cannot convert the JSON string because it contains keys with different casing. Please use the -AsHashTable switch instead.`
- File Downloads can be handled
## 1.3.6 (2023-03-03)
- If using a HashTable object for the `Invoke-ARAHRequest -Body` parameter it is only converted to json if the content type matches `json`.
## 1.3.5 (2023-01-18)
Expand Down
15 changes: 14 additions & 1 deletion ARAH/functions/Invoke-ARAHRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
.PARAMETER PagingHandler
Name of a registered PSFScriptBlock which should process the automatic paging of data.
.PARAMETER ConvertJsonAsHashtable
If set the json result will be converted as a HashTable
.EXAMPLE
$result = Invoke-ARAH -connection $this -path "/v4/auth/login" -method POST -body @{login = $credentials.UserName; password = $credentials.GetNetworkCredential().Password; language = "1"; authType = "sql" } -hideparameters $true
Expand All @@ -81,12 +84,14 @@
$Body,
[Hashtable] $URLParameter,
[string]$InFile,
[string]$OutFile,
[string]$ContentType,
[bool]$EnableException = $true,
[ValidateSet('CertificateCheck', 'HttpErrorCheck', 'HeaderValidation')]
[String[]]$SkipCheck = @(),
[string]$RequestModifier,
[string]$PagingHandler,
[switch]$ConvertJsonAsHashtable,
[switch]$EnablePaging
)
$uri = $connection.webServiceRoot + $path
Expand Down Expand Up @@ -138,6 +143,9 @@
If ($InFile) {
$restAPIParameter.InFile = $InFile
}
If ($OutFile) {
$restAPIParameter.OutFile = $OutFile
}

try {
If ($RequestModifier) {
Expand All @@ -146,6 +154,7 @@
}
Write-ARAHCallMessage $restAPIParameter
$response = Invoke-WebRequest @restAPIParameter
if($OutFile){return}
if ($PSBoundParameters.Debug) {
$global:invokeARAHrestAPIParameter = $restAPIParameter
Write-PSFMessage "Saving restAPIParameter to `$global:invokeARAHrestAPIParameter" -level Debug
Expand All @@ -164,7 +173,11 @@
$result = $connection.Charset.GetString([System.Text.Encoding]::GetEncoding(28591).getBytes($result))
}
if ($effectiveContentType -like '*json*') {
$result = $result | ConvertFrom-Json
if ($ConvertJsonAsHashtable){
$result = $result | ConvertFrom-Json -AsHashtable
}else{
$result = $result | ConvertFrom-Json
}
}
Write-PSFMessage "Response-Header: $($response.Headers|Format-Table|Out-String)" -Level Debug
Write-PSFMessage -Level Debug "result= $($result| ConvertTo-Json -WarningAction SilentlyContinue -Depth 5)"
Expand Down

0 comments on commit 10bdc51

Please sign in to comment.