Skip to main content
Solved

Getting information from the API


BGSICTSupport
Forum|alt.badge.img+6

Hi

We had a powershell script (pictured) that would Get information about Mobile Device Apps and who they were scoped to so that we could use this data else where. After one of the recent updates it has stopped working.

Does anyone have any idea as to why this would be?

Best answer by koalatee

Maybe TLS changes (10.6? or 10.7? can't remember). Try adding this to the top of your code.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
View original
Did this topic help you find an answer to your question?

10 replies

Forum|alt.badge.img+20
  • Employee
  • 77 replies
  • November 5, 2018

It looks like you're not specifying an Accept header, while Jamf Pro is capable of returning both XML and JSON, therefore you may be receiving XML or JSON when expecting the other. I don't know powershell well enough to know which you're expecting, but I'm guessing JSON, in which case line 19 should look something like the following:

$data = Invoke-restmethod -Method Get -Uri $uri$i -Credential $cred -Headers @{"accept"="application/json"}

BGSICTSupport
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 15 replies
  • November 5, 2018

Unfortunately the same issue. I just get our "There was a problem with" error.


Forum|alt.badge.img+11
  • Valued Contributor
  • 324 replies
  • November 5, 2018

I would imagine you were using XML and that it's now returning JSON. Try adding:

-Headers @{"Accept"="application/xml"}

Onto the end of your $data section.


BGSICTSupport
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 15 replies
  • November 5, 2018

Same thing annoyingly. This used to work perfectly.

Does anyone use a similar thing that works?


Forum|alt.badge.img+11
  • Valued Contributor
  • 324 replies
  • November 5, 2018

I would start by adding some write-host outputs into your script to see what you're getting. Can you post the exact output you get when you run the script? You've confirmed that the API is accessible via a web browser etc?


BGSICTSupport
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 15 replies
  • November 5, 2018

I normally run the below to run the script and output it to a csv file.

C:ScopedScriptsAppSyncAppSync.ps1 | Select-Object -Property DisplayName,AllJSSUsers,AllMobileDevices,LimitToUsers,Exclusions | Export-csv

I only have a csv file from when it worked which looks like the attached.

The output i get now is blank as this is all i get when i run the script.


Forum|alt.badge.img+11
  • Valued Contributor
  • 324 replies
  • November 5, 2018

It's the path then that's probably wrong. One way you can find out is to run the script again via the ISE, and then add a line $l and start typing in the path, powershell should offer you the options and you can then find out the correct path.


Forum|alt.badge.img+7
  • Contributor
  • 82 replies
  • Answer
  • November 5, 2018

Maybe TLS changes (10.6? or 10.7? can't remember). Try adding this to the top of your code.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Forum|alt.badge.img+11
  • Valued Contributor
  • 324 replies
  • November 5, 2018

@koalatee that could be it, I glossed over that line right at the top of my script!


BGSICTSupport
Forum|alt.badge.img+6
  • Author
  • Contributor
  • 15 replies
  • November 5, 2018

Thats the one. I would have never got that in a millions years. Thank you!!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings