# Invoke-Restmethod Outputting Strings

**URL:** <https://forums.powershell.org/t/invoke-restmethod-outputting-strings/7630>\
**Category:** PowerShell Help\
**Created:** [December 1, 2016, 2:24pm UTC](https://forums.powershell.org/t/invoke-restmethod-outputting-strings/7630 "2016-12-01T14:24:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![monterey610](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/monterey610/32/1080_2.png) [@monterey610](https://forums.powershell.org/u/monterey610)\
**Post date:** [December 1, 2016, 2:24pm UTC](https://forums.powershell.org/t/invoke-restmethod-outputting-strings/7630/1 "2016-12-01T14:24:43Z")

</div>

I work for a Microsoft Partner and we are a Cloud Solution Provider. The CSP Program has a wonderful ReST API I would like to turn into a PowerShell module for my personal edification and to easy some of my daily tasks with deploying a [ASP.NET](http://ASP.NET) website. The problem I have run into is when I call the API via Invoke-RestMethod I get a srtring that kind of looks like a JSON Object but I cant convert it from json. Belwo is my code for the Invoke-Restmethod. Can anyone see an issue with my code here?  
Headers match info found here = [https://msdn.microsoft.com/en-us/library/partnercenter/mt634673.aspx](https://msdn.microsoft.com/en-us/library/partnercenter/mt634673.aspx) and the content type is “application/json;charset=utf-8”. I tried UseBasicParsing and -UserAgent Parameter as well to no avail.

```
Invoke-RestMethod -Method Get -Uri 'https://api.partnercenter.microsoft.com/v1/customers?size=40 HTTP/1.1' -Headers $headers3 -ContentType $contentType
```

Output is here as a string:

```
{"totalCount":1,"items":[{"id":"9c0000-0000-4000-8824-63f000000","companyProfile":{"tenantId9c0000-0000-4000-8824-63f000000","domain":"sndbx.onmicrosoft.com","companyName":"SandBox","links":{"sel
f":{"uri":"/customers/9c0000-0000-4000-8824-63f000000/profiles/company","method":"GET","headers":[]}},"attributes":{"objectType":"CustomerCompanyProfile"}},"relationshipToPartner":"reseller","links":{"self":{"
uri":"/customers/9c0000-0000-4000-8824-63f000000","method":"GET","headers":[]}},"attributes":{"objectType":"Customer"}}],"links":{"self":{"uri":"/customers","method":"GET","headers":[]}},"attributes":{"objectT
ype":"Collection"}}
```

---

<div class="post-metadata">

**Author:** ![dweda](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dweda](https://forums.powershell.org/u/dweda)\
**Post date:** [December 3, 2016, 9:47am UTC](https://forums.powershell.org/t/invoke-restmethod-outputting-strings/7630/2 "2016-12-03T09:47:02Z")

</div>

I think you have tried the same things as I would have done.  
It looks like the response is somehow not really JSON because if it was JSON it would return a PSObject and not just string.  
Your response looks equal to the one on the MSDN page, what do you see when you only run

```
Invoke-RestMethod -Method Get -Uri '[https://api.partnercenter.microsoft.com/v1/customers?size=40](https://api.partnercenter.microsoft.com/v1/customers?size=40)
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/invoke-restmethod-outputting-strings/7630/3 "2024-05-16T20:39:47Z")

</div>


