# API v2 unexpected output converting curl to Powershell Invoke-RestMethod

**URL:** <https://community.dynatrace.com/t/api-v2-unexpected-output-converting-curl-to-powershell-invoke-restmethod/47406>\
**Category:** Dynatrace API\
**Tags:** dynatrace-managed, powershell, dynatrace-api\
**Created:** [August 30, 2024, 1:00pm UTC](https://community.dynatrace.com/t/api-v2-unexpected-output-converting-curl-to-powershell-invoke-restmethod/47406 "2024-08-30T13:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![runatyr](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/runatyr/32/11396_2.png) [@runatyr](https://community.dynatrace.com/u/runatyr)\
**Post date:** [August 30, 2024, 1:00pm UTC](https://community.dynatrace.com/t/api-v2-unexpected-output-converting-curl-to-powershell-invoke-restmethod/47406/1 "2024-08-30T13:00:08Z")

</div>

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.PNG](https://global.discourse-cdn.com/dynatrace/original/3X/b/1/b1a2ea50565fc713d00ef771e8d8e0eac3131aaa.png)

 ![Code_Convert.PNG](https://global.discourse-cdn.com/dynatrace/original/3X/4/7/47d687df4794476a2d8c6891548f9c52aaa73c21.jpeg)

$body = @{  
“metricSelector” = “ext:cloud.azure.microsoft\_sql.managedinstances.io\_requests”  
“resolution” = “1m”  
“entitySelector” = “type(custom\_device),entityName.equals(`“■■■-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](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](https://xnm19dypd01/e/52575bc0-1849-4837-8e18-8bc962f4407f/api/v2/metrics/query)” -Body $body -Headers $headers

---

<div class="post-metadata">

**Author:** ![runatyr](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/runatyr/32/11396_2.png) [@runatyr](https://community.dynatrace.com/u/runatyr)\
**Post date:** [September 11, 2024, 11:16am UTC](https://community.dynatrace.com/t/api-v2-unexpected-output-converting-curl-to-powershell-invoke-restmethod/47406/2 "2024-09-11T11:16:02Z")

</div>

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](https://global.discourse-cdn.com/dynatrace/original/3X/9/b/9b1a46d7b2fc0274f2fd23f96a15c6ba4694640e.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&nbsp; is the format.

 ![runatyr_1-1726053198684.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/f/0f230a4b2c01fd8496fed0a2e9b44e680a2811bd.png)

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

---

<div class="post-metadata">

**Author:** ![mrandant](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@mrandant](https://community.dynatrace.com/u/mrandant)\
**Post date:** [September 18, 2024, 1:59pm UTC](https://community.dynatrace.com/t/api-v2-unexpected-output-converting-curl-to-powershell-invoke-restmethod/47406/3 "2024-09-18T13:59:04Z")

</div>

(Invoke-RestMethod -Uri “[https://xnm19dypd01/e/52575bc0-1849-4837-8e18-8bc962f4407f/api/v2/metrics/query](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.
