Azure Advisor API - receiving 404

Dan 0 Reputation points
2023-05-23T16:02:08.1366667+00:00

Hi,

I'm trying to create an Azure Advisor Recommendation digest using the API by following this process: https://learn.microsoft.com/en-us/rest/api/advisor/configurations/create-in-subscription?tabs=HTTP

I'm using Powershell and Azure modules to interact with the REST API but I'm getting a 404. I've also tried through the "try it" link on that documentation page (where I can select my subscription from a dropdown list after I've authenticated) and I get the same issue.

My code is something like this:

$azContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$authHeader = @{
    'Content-Type'='application/json'
    'Authorization'='Bearer ' + $token.AccessToken
}


$advisorDigestBody = @{

  "properties" = @{
      "lowCpuThreshold" = 5
      "duration" = "7"
      "exclude" = false
      "digests" = @(
        @{
          "name" = "test-digest"
          "actionGroupResourceId" = "/subscriptions/XXXXXXX-XXXX-XXXXXX-XXXXXX-XXXXX/resourceGroups/rg01/providers/Microsoft.Insights/actiongroups/my-action-group-01"
          "frequency" = 30
          "categories" = @(
            "Cost"
          )
        "language" = "en"
        "state" = "Active"
        }
      )
    }
  } | ConvertTo-Json -Depth 5


$createRGUri = "https://management.azure.com/subscriptions/XXXXXXX-XXXX-XXXXXX-XXXXXX-XXXXX/resourceGroups/rg01/providers/Microsoft.Advisor/configurations/default?api-version=2023-01-01"


Invoke-RestMethod -Uri $createRGUri -Method Put -Headers $authHeader -Body $advisorDigestBody

It's possibly I'm just not using the right kind of call to the API to do what I need, but I can't seem to get around this 404 issue. The Subscription and Resource Group definitely exist and my account has access to them. I can see them in the portal. I ran the Set-AZContext command before putting my script together so I'm also targetting the subscription as well.

Any ideas where I'm going wrong?

Azure Advisor
Azure Advisor
An Azure personalized recommendation engine that helps users follow best practices to optimize Azure deployments.
64 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.