30 Aug 2024 02:00 PM - last edited on 02 Sep 2024 07:26 AM by MaciejNeumann
Hello:
We are attempting to convert the curl command to a powershell Invoke-RestMethod command in the PIA v2 for GET /metrics/query
I am unclear as to why I do not get the data returned with Invoke-RestMethod but CURL works.
Information is returned, but not the data from the API.
What is happening and does anyone see what needs changed to retrieve the data?
Thank you,
Runatyr
$body = @{
"metricSelector" = "ext:cloud.azure.microsoft_sql.managedinstances.io_requests"
"resolution" = "1m"
"entitySelector" = "type(custom_device),entityName.equals(`"bwc-sqlmi-peachpoc`")"
}
$headers = @{
"accept" = "application/json; charset=utf-8"
"Authorization" = "Api-Token dt0c01.xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
$response = Invoke-RestMethod -Uri "https://xnm19dypd01/e/52575bc0-1849-4837-8e18-8bc962f4407f/api/v2/metrics/query" -Body $body -Headers $headers
Invoke-RestMethod -Uri "https://xnm19dypd01/e/52575bc0-1849-4837-8e18-8bc962f4407f/api/v2/metrics/query" -Body $body -Headers $headers
Solved! Go to Solution.
11 Sep 2024 12:16 PM
Update:
I have a PowerShell Script that is using the Invoke-RestMethod.
However, the data returned looks like this in PowerShell.
I don't see the values expected values.
This is what I see.
How do I go about accessing the data in this format?
When I query the API directly with cURL(PowerShell) in the Dynatrace API .. this is the format.
Any ideas how to access the data when returned in that first format using Invoke-RestMethod? and not cURL?
18 Sep 2024 02:59 PM
(Invoke-RestMethod -Uri "https://xnm19dypd01/e/52575bc0-1849-4837-8e18-8bc962f4407f/api/v2/metrics/query" -Body $body -Headers $headers).result | ConvertTo-Json
or
$Response.result | ConvertTo-Json
Converting the result to JSON will get you mostly the same result as your curl output.