Author Posts

December 1, 2016 at 7:54 pm

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 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 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"}} 

December 3, 2016 at 3:17 pm

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