Policy Status from Jamf Pro API

msay0
New Contributor

I am attempting to get policy statuses for computers from the API. I found a few older posts (from around 2015) saying it wasn't possible, but I also found this post (https://community.jamf.com/t5/jamf-pro/extract-a-jamf-policy-status/m-p/252920) that gave me some hope. I connected with PowerShell and was trying this:

$url = "https://domain.jamfcloud.com/JSSResource/policies/id/318"

Invoke-RestMethod -Uri $url -Method Get -Headers @{"Authorization" = "Bearer $token"}

I get a response, but without any information:

xml                            policy
---                            ------
version="1.0" encoding="UTF-8" policy

Any ideas on returning policy statuses with the Jamf Pro API? 

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Yeah, unfortunately it's only available right now from the classic API. But is there a reason you can't use that? Both APIs are viable for the time being. Eventually I imagine Jamf will remove the classic API, but probably not until many of the items only available in Classic make their way into the new one.

View solution in original post

9 REPLIES 9

MikePh
New Contributor III
New Contributor III

What are you looking for when you refer to 'policy status'? Like if it completed or failed? What is the goal you're trying to achieve? 

msay0
New Contributor

I would like to see if it completed or failed for the assigned computers. Essentially, just see the policy status that can be viewed in the dashboard. 

mm2270
Legendary Contributor III

To my knowledge, it's only possible to pull history from a device, meaning you can see the policies that have run on an individual computer, but I don't think the API lets you see an entire policy's logs. It would be a nice option to add to the API, but I don't think it currently exists.

msay0
New Contributor

I could likely make it work from pulling the history from a device. Is that available with the Jamf Pro API? I see computerhistory with the Classic API, but I don't see that with the Pro API.

mm2270
Legendary Contributor III

Yeah, unfortunately it's only available right now from the classic API. But is there a reason you can't use that? Both APIs are viable for the time being. Eventually I imagine Jamf will remove the classic API, but probably not until many of the items only available in Classic make their way into the new one.

msay0
New Contributor

If I can get the classic API to work, I would have no problem using it. I am able to get a bearer token and use the pro API, but I get access denied each time I try a URL for the classic API. I have the required privileges using an API client and secret.

From what I can find, it seems the method of acquiring a token is the same for the classic and pro APIs, so I'm really not sure where the issue is. 

msay0
New Contributor

Please disregard my previous response, I had a typo in my URL. I am getting a reponse using the following URL: 'https://domain.jamfcloud.com/JSSResource/computerhistory/id/id' but the response doesn't have any actual information it just returns: 

xml                            computer_history
---                            ----------------
version="1.0" encoding="UTF-8" computer_history

MLBZ521
Contributor III

This looks like you're using PowerShell.  The response comes back as an object and you would have to "dive" down into that nested object.  It will not simply "echo" the entire object to shell.

msay0
New Contributor

I got it working with changing around the output format. Thank you for the assistance.