cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API v2 unexpected output converting curl to Powershell Invoke-RestMethod

runatyr
Organizer

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

 

 

API_Results.PNGCode_Convert.PNG

$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

2 REPLIES 2

runatyr
Organizer

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.

runatyr_0-1726053105066.png

 

 

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.

runatyr_1-1726053198684.png

 

Any ideas how to access the data when returned in that first format using Invoke-RestMethod? and not cURL?

 

(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.

 

Featured Posts