Updated BuildNewURI to be compatible with new version of netbox

The way the parameters are done for the API has changed.
`Get-NetboxIPAMAddress -Status 'dhcp' -Query 'dns_name__ic=example.org'`
Used to return `/api/ipam/ip-addresses/?q=dns_name__ic=example.org&status=dhcp`

Now it returns `/api/ipam/ip-addresses/?dns_name__ic=bel082224&status=dhcp`
This commit is contained in:
Wago Louage 2024-08-28 16:52:24 +02:00 committed by GitHub
parent 7275591ac8
commit 00cdedbbab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -333,16 +333,25 @@ function BuildNewURI {
Write-Verbose " URIPath: $($uriBuilder.Path)" Write-Verbose " URIPath: $($uriBuilder.Path)"
if ($parameters) { if ($Parameters) {
# Loop through the parameters and use the HttpUtility to create a Query string # Loop through the parameters and use the HttpUtility to create a Query string
[System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) [System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString($uriBuilder.Query)
foreach ($param in $Parameters.GetEnumerator()) { foreach ($param in $Parameters.GetEnumerator()) {
Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)" Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)"
if ($param.Key -eq 'q') {
# Append the query string directly
$uriBuilder.Query = $uriBuilder.Query.TrimStart('?') + '&' + $param.Value
}
else {
$URIParams[$param.Key] = $param.Value $URIParams[$param.Key] = $param.Value
} }
}
$uriBuilder.Query = $URIParams.ToString() # Combine the existing query with new parameters
$existingQuery = $uriBuilder.Query.TrimStart('?')
$newQuery = $URIParams.ToString()
$uriBuilder.Query = ($existingQuery + '&' + $newQuery).Trim('&')
} }
Write-Verbose " Completed building URIBuilder" Write-Verbose " Completed building URIBuilder"