Skip to content

Commit 7d528ff

Browse files
committed
Update Resource Graph request to POST and set default content type
Changed the Resource Graph API call in Invoke-ListApiTest.ps1 from a GET to a POST request with a JSON body and updated the API version. Set the default ContentType to 'application/json' in New-CIPPAzRestRequest.ps1 to ensure correct request formatting.
1 parent 448994e commit 7d528ff

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListApiTest.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function Invoke-ListApiTest {
3333

3434
# test New-CIPPAzRestRequest KQL for resource graph
3535
$Query = 'Resources | project name, type'
36-
$Request = New-CIPPAzRestRequest -Method GET -Resource 'https://management.azure.com/' -ApiVersion '2021-03-01' -Endpoint 'providers/Microsoft.ResourceGraph/resources' -QueryParameters @{ 'query' = $Query }
36+
$Json = ConvertTo-Json -Depth 10 -Compress -InputObject @{ query = $Query }
37+
$Request = New-CIPPAzRestRequest -Method POST -Resource 'https://management.azure.com/' -Endpoint 'providers/Microsoft.ResourceGraph/resources?api-version=2022-10-01' -Body $Json
3738
}
3839
$Response.AllowedTenants = $script:CippAllowedTenantsStorage.Value
3940
$Response.AllowedGroups = $script:CippAllowedGroupsStorage.Value

Modules/CIPPCore/Public/GraphHelper/New-CIPPAzRestRequest.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function New-CIPPAzRestRequest {
7070
[hashtable]$Headers = @{},
7171

7272
[Parameter(Mandatory = $false)]
73-
[string]$ContentType,
73+
[string]$ContentType = 'application/json',
7474

7575
[Parameter(Mandatory = $false)]
7676
[switch]$SkipHttpErrorCheck,
@@ -137,10 +137,10 @@ function New-CIPPAzRestRequest {
137137

138138
# Build Invoke-RestMethod parameters
139139
$RestMethodParams = @{
140-
Uri = $Uri
141-
Method = $Method
142-
Headers = $RequestHeaders
143-
ErrorAction = $ErrorActionPreference
140+
Uri = $Uri
141+
Method = $Method
142+
Headers = $RequestHeaders
143+
ErrorAction = $ErrorActionPreference
144144
}
145145

146146
if ($Body) {

0 commit comments

Comments
 (0)