jamf pro API - v1/computers-inventory-detail/{id} - Cutting the JSON only to get all static Groups

MathiasO_TK
New Contributor II

Hey Guys,

I´m currently looking to get a List of Static Groups from a specific computer. 
I found the API command: v1/computers-inventory-detail/{id} getting a large JSON with the Details.

Now I want to cut it down to:
1. only the Arrays from Key "groupMemberships"
2. maybe to all Arrays with "smartGroup=false"

I tried with plutil -extract, but I cant get the right Keypath...

Here is an example of my JSON:

"id" : "866",
  "udid" : "6A94F1BD-XXXX-XXXXX-XXXX-ECB58DFA0B61",
  "general" : {
    "name" : "MC-XXXXXXXX",
    "lastIpAddress" : "XX.XX.XX.XX",
    "lastReportedIp" : "XX.XX.XXX.XX",
    "jamfBinaryVersion" : "11.7.1-t1721056075",
    "platform" : "Mac",
    "barcode1" : null,
    "barcode2" : null,
    "assetTag" : null,
    "remoteManagement" : {
      "managed" : true,
      "managementUsername" : null
    },
    "supervised" : true,
    "mdmCapable" : {
      "capable" : true,
      "capableUsers" : [ "XXXXXX" ]
    },
    "reportDate" : "2024-08-21T06:55:17.421Z",
    "lastContactTime" : "2024-08-21T08:41:21.63Z",
    "lastCloudBackupDate" : null,
    "lastEnrolledDate" : "2024-07-01T08:28:35.256Z",
    "mdmProfileExpiration" : "2026-07-01T08:27:37Z",
    "initialEntryDate" : "2024-07-01",
    "distributionPoint" : null,
    "site" : {
      "id" : "-1",
      "name" : "None"
}
"diskEncryption" : {
    "individualRecoveryKeyValidityStatus" : "VALID",
    "institutionalRecoveryKeyPresent" : false,
    "diskEncryptionConfigurationName" : "FileVault_TK",
    "fileVault2EligibilityMessage" : "Eligible",
    "fileVault2EnabledUserNames" : [ "P231180" ],
    "bootPartitionEncryptionDetails" : {
      "partitionName" : "Macintosh HD (Boot Partition)",
      "partitionFileVault2State" : "ENCRYPTED",
      "partitionFileVault2Percent" : 100
    }
"plugins" : [ ],
 "groupMemberships" : [ {
    "groupId" : "1",
    "groupName" : "All Managed Clients",
    "smartGroup" : true
  }, {
    "groupId" : "12",
    "groupName" : "DEP enrolled Client",
    "smartGroup" : true
  }, {
    "groupId" : "15",
    "groupName" : "ComputerName",
    "smartGroup" : true
  }, {
    "groupId" : "18",
    "groupName" : "FileVault",
    "smartGroup" : true
  }, {
    "groupId" : "20",
    "groupName" : "NameSet",
    "smartGroup" : true
  }, {
    "groupId" : "23",
    "groupName" : "Adobe_CreativeCloud",
    "smartGroup" : false 
  }, {
    "groupId" : "255",
    "groupName" : "Pilots",
    "smartGroup" : false
  }, {
    "groupId" : "256",
    "groupName" : "TS.CA Pilot",
    "smartGroup" : false
  } ],




1 ACCEPTED SOLUTION

MathiasO_TK
New Contributor II

Solved it in an rookie way :D 

As I just needed the values of the GroupIDs I got an textfile as output and greped it the way I needed
here is the cut out with variables:

# Inventory Collection from Computer 
inventory_details=$(curl -s -H "Accept: application/json" -H "Authorization: Bearer ${bearerToken}" "${url}/api/v1/computers-inventory-detail/$deviceID" -X GET)
echo "$inventory_details" >> $txt_tmp

# Use grep to delete everything except 2 Lines with: "smartGroup" : false
grep -B 2 '"smartGroup" : false' $txt_tmp > $txt_tmp2

# cutting only Group IDs and writing into txt file
awk -F'"' '/"groupId" :/ {print $4}' $txt_tmp2 > $GROUP_ID_FILE



 

View solution in original post

2 REPLIES 2

talkingmoose
Moderator
Moderator

I can see a couple ways to do this.

A simple way would be to use grep and its --before-context option to find “smartGroup” : false and then clean up the results with sed.

Or you could use xpath and its preceding-sibling syntax, which is a little more complicated but would result in cleaner results with one command. I have an example of how to do this with following-sibling here:

https://gist.github.com/talkingmoose/07ae935169e863b377c2290c40a660e0

MathiasO_TK
New Contributor II

Solved it in an rookie way :D 

As I just needed the values of the GroupIDs I got an textfile as output and greped it the way I needed
here is the cut out with variables:

# Inventory Collection from Computer 
inventory_details=$(curl -s -H "Accept: application/json" -H "Authorization: Bearer ${bearerToken}" "${url}/api/v1/computers-inventory-detail/$deviceID" -X GET)
echo "$inventory_details" >> $txt_tmp

# Use grep to delete everything except 2 Lines with: "smartGroup" : false
grep -B 2 '"smartGroup" : false' $txt_tmp > $txt_tmp2

# cutting only Group IDs and writing into txt file
awk -F'"' '/"groupId" :/ {print $4}' $txt_tmp2 > $GROUP_ID_FILE