Skip to content

Commit

Permalink
Automated Switch to POST-Request if URI is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonzel committed Apr 6, 2024
1 parent 81afaa7 commit 33d44ed
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Public/Get-AutotaskAPIResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ function Get-AutotaskAPIResource {
$body = $SearchQuery
}
Default {
$ResourceURL = ("$($ResourceURL.name)/query?search=$SearchQuery" -replace '{PARENTID}', '')
if (($Script:AutotaskBaseURI.Length + $ResourceURL.name.Length + $SearchQuery.Length + 15 + 50) -ge 2100){
#15 characters for "//query?search="
#TODO: Calculation does not include Overwritten ParentID and is currently a better estimation. Therefore a "safe factor" of +50 chars is used
Write-Information "Using POST-Request as Request exceeded limit of 2100 characters. You can use -Method GET/POST to set a fixed Method."
$ResourceURL = ("$($ResourceURL.name)/query" -replace '{PARENTID}', '')
$body = $SearchQuery
$Method = "POST"
} else {
$ResourceURL = ("$($ResourceURL.name)/query?search=$SearchQuery" -replace '{PARENTID}', '')
}
}
}
}
Expand Down

0 comments on commit 33d44ed

Please sign in to comment.