Getting information from the API

BGSICTSupport
New Contributor III

Hi

We had a powershellb795dbb5e29c489a91c29c7a9c29bff0 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?

1 ACCEPTED SOLUTION

koalatee
Contributor II

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 solution in original post

10 REPLIES 10

SamF
Contributor

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
New Contributor III

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

allanp81
Valued Contributor

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
New Contributor III

Same thing annoyingly. This used to work perfectly.

Does anyone use a similar thing that works?

allanp81
Valued Contributor

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
New Contributor III

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. 2d1a4f9b25814b57b6d58ffd59b334f9

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

allanp81
Valued Contributor

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.

koalatee
Contributor II

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 solution in original post

allanp81
Valued Contributor

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

BGSICTSupport
New Contributor III

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